aboutsummaryrefslogtreecommitdiffstats
path: root/hostapd/ctrl_iface.c
diff options
context:
space:
mode:
authorJouni Malinen <jouni.malinen@atheros.com>2009-05-06 08:31:45 (GMT)
committerJouni Malinen <j@w1.fi>2009-11-22 08:57:09 (GMT)
commit83a88a015c7a52309632b2b96fd0c5f2c459d7cd (patch)
tree18cf7ea5653912f3000047d72380b7eaf8d7ac4d /hostapd/ctrl_iface.c
parent6866e32c9e9a3a108da21a694fcf70aec3c5a869 (diff)
downloadhostap-06-83a88a015c7a52309632b2b96fd0c5f2c459d7cd.zip
hostap-06-83a88a015c7a52309632b2b96fd0c5f2c459d7cd.tar.gz
hostap-06-83a88a015c7a52309632b2b96fd0c5f2c459d7cd.tar.bz2
Add code to re-use an existing ctrl_iface socket file
Port the code from wpa_supplicant to re-use an existing ctrl_iface socket file if the file does not seem to be in use. This allows hostapd to recover from unclean shutdown of the control interface. (cherry picked from commit 617d1555479aecf3bf13e35202a46c63e8d19052)
Diffstat (limited to 'hostapd/ctrl_iface.c')
-rw-r--r--hostapd/ctrl_iface.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
index a69a7ef..15c7873 100644
--- a/hostapd/ctrl_iface.c
+++ b/hostapd/ctrl_iface.c
@@ -450,8 +450,35 @@ int hostapd_ctrl_iface_init(struct hostapd_data *hapd)
goto fail;
os_strlcpy(addr.sun_path, fname, sizeof(addr.sun_path));
if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
- perror("bind(PF_UNIX)");
- goto fail;
+ wpa_printf(MSG_DEBUG, "ctrl_iface bind(PF_UNIX) failed: %s",
+ strerror(errno));
+ if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+ wpa_printf(MSG_DEBUG, "ctrl_iface exists, but does not"
+ " allow connections - assuming it was left"
+ "over from forced program termination");
+ if (unlink(fname) < 0) {
+ perror("unlink[ctrl_iface]");
+ wpa_printf(MSG_ERROR, "Could not unlink "
+ "existing ctrl_iface socket '%s'",
+ fname);
+ goto fail;
+ }
+ if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) <
+ 0) {
+ perror("bind(PF_UNIX)");
+ goto fail;
+ }
+ wpa_printf(MSG_DEBUG, "Successfully replaced leftover "
+ "ctrl_iface socket '%s'", fname);
+ } else {
+ wpa_printf(MSG_INFO, "ctrl_iface exists and seems to "
+ "be in use - cannot override it");
+ wpa_printf(MSG_INFO, "Delete '%s' manually if it is "
+ "not used anymore", fname);
+ os_free(fname);
+ fname = NULL;
+ goto fail;
+ }
}
if (hapd->conf->ctrl_interface_gid_set &&