diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c index 52dfc9f33..7e6ac2375 100644 --- a/hostapd/hostapd_cli.c +++ b/hostapd/hostapd_cli.c @@ -1444,7 +1444,7 @@ int main(int argc, char *argv[]) } } - if (daemonize && os_daemonize(pid_file)) + if (daemonize && os_daemonize(pid_file) && eloop_sock_requeue()) return -1; if (interactive) diff --git a/hostapd/main.c b/hostapd/main.c index 4913cbdef..1b9002cf2 100644 --- a/hostapd/main.c +++ b/hostapd/main.c @@ -408,9 +408,16 @@ static int hostapd_global_run(struct hapd_interfaces *ifaces, int daemonize, } #endif /* EAP_SERVER_TNC */ - if (daemonize && os_daemonize(pid_file)) { - wpa_printf(MSG_ERROR, "daemon: %s", strerror(errno)); - return -1; + if (daemonize) { + if (os_daemonize(pid_file)) { + wpa_printf(MSG_ERROR, "daemon: %s", strerror(errno)); + return -1; + } + if (eloop_sock_requeue()) { + wpa_printf(MSG_ERROR, "eloop_sock_requeue: %s", + strerror(errno)); + return -1; + } } eloop_run(); diff --git a/src/utils/eloop.c b/src/utils/eloop.c index 8647229b8..fda1a83e4 100644 --- a/src/utils/eloop.c +++ b/src/utils/eloop.c @@ -525,6 +525,12 @@ static void eloop_sock_table_dispatch(struct epoll_event *events, int nfds) #endif /* CONFIG_ELOOP_EPOLL */ +int eloop_sock_requeue(void) +{ + return 0; +} + + static void eloop_sock_table_destroy(struct eloop_sock_table *table) { if (table) { diff --git a/src/utils/eloop.h b/src/utils/eloop.h index 07b8c0dc3..97af16f01 100644 --- a/src/utils/eloop.h +++ b/src/utils/eloop.h @@ -312,6 +312,14 @@ int eloop_register_signal_terminate(eloop_signal_handler handler, int eloop_register_signal_reconfig(eloop_signal_handler handler, void *user_data); +/** + * eloop_sock_requeue - Requeue sockets + * + * Requeue sockets after forking because some implementations require this, + * such as epoll and kqueue. + */ +int eloop_sock_requeue(void); + /** * eloop_run - Start the event loop * diff --git a/src/utils/eloop_win.c b/src/utils/eloop_win.c index de47fb218..9c8b12be8 100644 --- a/src/utils/eloop_win.c +++ b/src/utils/eloop_win.c @@ -692,3 +692,9 @@ void eloop_wait_for_read_sock(int sock) WSAEventSelect(sock, event, 0); WSACloseEvent(event); } + + +int eloop_sock_requeue(void) +{ + return 0; +} diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c index 1aea0a656..265f72c99 100644 --- a/wpa_supplicant/wpa_cli.c +++ b/wpa_supplicant/wpa_cli.c @@ -4441,7 +4441,7 @@ int main(int argc, char *argv[]) } } - if (daemonize && os_daemonize(pid_file)) + if (daemonize && os_daemonize(pid_file) && eloop_sock_requeue()) return -1; if (action_file) diff --git a/wpa_supplicant/wpa_priv.c b/wpa_supplicant/wpa_priv.c index fa5a6ded5..3f91cc16a 100644 --- a/wpa_supplicant/wpa_priv.c +++ b/wpa_supplicant/wpa_priv.c @@ -1128,7 +1128,7 @@ int main(int argc, char *argv[]) interfaces = iface; } - if (daemonize && os_daemonize(pid_file)) + if (daemonize && os_daemonize(pid_file) && eloop_sock_requeue()) goto out; eloop_register_signal_terminate(wpa_priv_terminate, NULL); diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c index 03b135332..c3c1f1472 100644 --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c @@ -5221,7 +5221,8 @@ int wpa_supplicant_run(struct wpa_global *global) struct wpa_supplicant *wpa_s; if (global->params.daemonize && - wpa_supplicant_daemon(global->params.pid_file)) + (wpa_supplicant_daemon(global->params.pid_file) || + eloop_sock_requeue())) return -1; if (global->params.wait_for_monitor) {