aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2009-01-31 20:22:09 (GMT)
committerJouni Malinen <j@w1.fi>2009-02-08 10:28:23 (GMT)
commit3cbcc5ef9fca4371341a8605790a473af49f0040 (patch)
tree74eb8426f3740cc9188295dab1b464ba222e8570 /src
parentaabc8064cdadffc315a2b2d9362176e545c64f82 (diff)
downloadhostap-06-3cbcc5ef9fca4371341a8605790a473af49f0040.zip
hostap-06-3cbcc5ef9fca4371341a8605790a473af49f0040.tar.gz
hostap-06-3cbcc5ef9fca4371341a8605790a473af49f0040.tar.bz2
Remove orphaned wpa_cli control socket on EADDRINUSE
If the bind() on /tmp/wpa_ctrl_<pid>_<in-proc-counter> fails with EADDRINUSE, there is an existing socket file with the name we are trying to create. Since getpid() is unique, there cannot be another process using that socket and we can just unlink the file and try again. This can speed up client connection if wpa_cli is killed without allowing it to clean up the socket file. [Bug 288] (cherry picked from commit 6e488ff03c5af513f7768364f3cdd890ef98b0bd)
Diffstat (limited to 'src')
-rw-r--r--src/common/wpa_ctrl.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/common/wpa_ctrl.c b/src/common/wpa_ctrl.c
index e411602..2b4e3aa 100644
--- a/src/common/wpa_ctrl.c
+++ b/src/common/wpa_ctrl.c
@@ -64,6 +64,7 @@ struct wpa_ctrl * wpa_ctrl_open(const char *ctrl_path)
static int counter = 0;
int ret;
size_t res;
+ int tries = 0;
ctrl = os_malloc(sizeof(*ctrl));
if (ctrl == NULL)
@@ -77,15 +78,28 @@ struct wpa_ctrl * wpa_ctrl_open(const char *ctrl_path)
}
ctrl->local.sun_family = AF_UNIX;
+ counter++;
+try_again:
ret = os_snprintf(ctrl->local.sun_path, sizeof(ctrl->local.sun_path),
- "/tmp/wpa_ctrl_%d-%d", getpid(), counter++);
+ "/tmp/wpa_ctrl_%d-%d", getpid(), counter);
if (ret < 0 || (size_t) ret >= sizeof(ctrl->local.sun_path)) {
close(ctrl->s);
os_free(ctrl);
return NULL;
}
+ tries++;
if (bind(ctrl->s, (struct sockaddr *) &ctrl->local,
sizeof(ctrl->local)) < 0) {
+ if (errno == EADDRINUSE && tries < 2) {
+ /*
+ * getpid() returns unique identifier for this instance
+ * of wpa_ctrl, so the existing socket file must have
+ * been left by unclean termination of an earlier run.
+ * Remove the file and try again.
+ */
+ unlink(ctrl->local.sun_path);
+ goto try_again;
+ }
close(ctrl->s);
os_free(ctrl);
return NULL;