diff options
author | Dmitry Shmidt <dimitrysh@google.com> | 2011-03-25 13:37:18 -0700 |
---|---|---|
committer | Dmitry Shmidt <dimitrysh@google.com> | 2011-03-25 13:37:18 -0700 |
commit | eea19f1d855b9434313fbb9447a23caf8123aa58 (patch) | |
tree | fb509c774c1df2b5d7309aacf688906148d06262 | |
parent | 770062f22548c414fc001dbb3e1db67b5630d1e5 (diff) | |
download | android_hardware_libhardware_legacy-eea19f1d855b9434313fbb9447a23caf8123aa58.tar.gz android_hardware_libhardware_legacy-eea19f1d855b9434313fbb9447a23caf8123aa58.tar.bz2 android_hardware_libhardware_legacy-eea19f1d855b9434313fbb9447a23caf8123aa58.zip |
Move wpa_ctrl_cleanup() function to wifi_wpa_ctrl_cleanup()
Change-Id: I557a2ac10ebb226508ffccfbfeca7f326912ed04
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
-rw-r--r-- | wifi/Android.mk | 3 | ||||
-rw-r--r-- | wifi/wifi.c | 42 |
2 files changed, 44 insertions, 1 deletions
diff --git a/wifi/Android.mk b/wifi/Android.mk index 5d94fb8..70e1b7b 100644 --- a/wifi/Android.mk +++ b/wifi/Android.mk @@ -1,5 +1,8 @@ # Copyright 2006 The Android Open Source Project +LOCAL_CFLAGS += -DCONFIG_CTRL_IFACE_CLIENT_DIR=\"/data/misc/wifi/sockets\" +LOCAL_CFLAGS += -DCONFIG_CTRL_IFACE_CLIENT_PREFIX=\"wpa_ctrl_\" + ifdef WIFI_DRIVER_MODULE_PATH LOCAL_CFLAGS += -DWIFI_DRIVER_MODULE_PATH=\"$(WIFI_DRIVER_MODULE_PATH)\" endif diff --git a/wifi/wifi.c b/wifi/wifi.c index 132f723..3f2de17 100644 --- a/wifi/wifi.c +++ b/wifi/wifi.c @@ -18,6 +18,7 @@ #include <fcntl.h> #include <errno.h> #include <string.h> +#include <dirent.h> #include "hardware_legacy/wifi.h" #include "libwpa_client/wpa_ctrl.h" @@ -331,6 +332,45 @@ int ensure_config_file_exists() return 0; } +/** + * wifi_wpa_ctrl_cleanup() - Delete any local UNIX domain socket files that + * may be left over from clients that were previously connected to + * wpa_supplicant. This keeps these files from being orphaned in the + * event of crashes that prevented them from being removed as part + * of the normal orderly shutdown. + */ +void wifi_wpa_ctrl_cleanup(void) +{ + DIR *dir; + struct dirent entry; + struct dirent *result; + size_t dirnamelen; + size_t maxcopy; + char pathname[PATH_MAX]; + char *namep; + char *local_socket_dir = CONFIG_CTRL_IFACE_CLIENT_DIR; + char *local_socket_prefix = CONFIG_CTRL_IFACE_CLIENT_PREFIX; + + if ((dir = opendir(local_socket_dir)) == NULL) + return; + + dirnamelen = (size_t)snprintf(pathname, sizeof(pathname), "%s/", local_socket_dir); + if (dirnamelen >= sizeof(pathname)) { + closedir(dir); + return; + } + namep = pathname + dirnamelen; + maxcopy = PATH_MAX - dirnamelen; + while (readdir_r(dir, &entry, &result) == 0 && result != NULL) { + if (strncmp(entry.d_name, local_socket_prefix, strlen(local_socket_prefix)) == 0) { + if (strlcpy(namep, entry.d_name, maxcopy) < maxcopy) { + unlink(pathname); + } + } + } + closedir(dir); +} + int wifi_start_supplicant() { char daemon_cmd[PROPERTY_VALUE_MAX]; @@ -354,7 +394,7 @@ int wifi_start_supplicant() } /* Clear out any stale socket files that might be left over. */ - wpa_ctrl_cleanup(); + wifi_wpa_ctrl_cleanup(); #ifdef HAVE_LIBC_SYSTEM_PROPERTIES /* |