aboutsummaryrefslogtreecommitdiffstats
path: root/src/common/wpa_ctrl.c
diff options
context:
space:
mode:
authorDmitry Shmidt <dimitrysh@google.com>2011-10-18 14:27:53 (GMT)
committerJouni Malinen <j@w1.fi>2011-10-18 14:27:53 (GMT)
commited3eecd786cd4c18e442ecc5c743692689e38a6e (patch)
tree2083288b622ab028b17fdb7aa8e8c4c041fd1b9b /src/common/wpa_ctrl.c
parent67e838fd0cecc38a28f3219662294ce46fe6d112 (diff)
downloadhostap-ed3eecd786cd4c18e442ecc5c743692689e38a6e.zip
hostap-ed3eecd786cd4c18e442ecc5c743692689e38a6e.tar.gz
hostap-ed3eecd786cd4c18e442ecc5c743692689e38a6e.tar.bz2
Android: Add wpa_ctrl_cleanup()
This function can be used to clean up local UNIX domain socket files that may be left over from clients that were previously connected to wpa_supplicant. At least for now, this is only available for Android builds.
Diffstat (limited to 'src/common/wpa_ctrl.c')
-rw-r--r--src/common/wpa_ctrl.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/common/wpa_ctrl.c b/src/common/wpa_ctrl.c
index 88d3a02..3b25f77 100644
--- a/src/common/wpa_ctrl.c
+++ b/src/common/wpa_ctrl.c
@@ -21,6 +21,7 @@
#endif /* CONFIG_CTRL_IFACE_UNIX */
#ifdef ANDROID
+#include <dirent.h>
#include <cutils/sockets.h>
#include "private/android_filesystem_config.h"
#endif /* ANDROID */
@@ -175,6 +176,56 @@ void wpa_ctrl_close(struct wpa_ctrl *ctrl)
os_free(ctrl);
}
+
+#ifdef ANDROID
+/**
+ * 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 wpa_ctrl_cleanup(void)
+{
+ DIR *dir;
+ struct dirent entry;
+ struct dirent *result;
+ size_t dirnamelen;
+ int prefixlen = os_strlen(CONFIG_CTRL_IFACE_CLIENT_PREFIX);
+ size_t maxcopy;
+ char pathname[PATH_MAX];
+ char *namep;
+
+ if ((dir = opendir(CONFIG_CTRL_IFACE_CLIENT_DIR)) == NULL)
+ return;
+
+ dirnamelen = (size_t) os_snprintf(pathname, sizeof(pathname), "%s/",
+ CONFIG_CTRL_IFACE_CLIENT_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 (os_strncmp(entry.d_name, CONFIG_CTRL_IFACE_CLIENT_PREFIX,
+ prefixlen) == 0) {
+ if (os_strlcpy(namep, entry.d_name, maxcopy) < maxcopy)
+ unlink(pathname);
+ }
+ }
+ closedir(dir);
+}
+#endif /* ANDROID */
+
+#else /* CONFIG_CTRL_IFACE_UNIX */
+
+#ifdef ANDROID
+void wpa_ctrl_cleanup(void)
+{
+}
+#endif /* ANDROID */
+
#endif /* CONFIG_CTRL_IFACE_UNIX */