Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/bsd/wpa/dist Re-queue kqueue events after forking.
details: https://anonhg.NetBSD.org/src/rev/89c285e93788
branches: trunk
changeset: 343045:89c285e93788
user: roy <roy%NetBSD.org@localhost>
date: Wed Jan 20 17:03:35 2016 +0000
description:
Re-queue kqueue events after forking.
diffstat:
external/bsd/wpa/dist/hostapd/hostapd_cli.c | 2 +-
external/bsd/wpa/dist/hostapd/main.c | 13 +-
external/bsd/wpa/dist/src/utils/eloop.c | 164 ++++++++++++-----
external/bsd/wpa/dist/src/utils/eloop.h | 8 +
external/bsd/wpa/dist/wpa_supplicant/wpa_cli.c | 2 +-
external/bsd/wpa/dist/wpa_supplicant/wpa_supplicant.c | 3 +-
6 files changed, 132 insertions(+), 60 deletions(-)
diffs (290 lines):
diff -r 96f211718804 -r 89c285e93788 external/bsd/wpa/dist/hostapd/hostapd_cli.c
--- a/external/bsd/wpa/dist/hostapd/hostapd_cli.c Wed Jan 20 15:43:05 2016 +0000
+++ b/external/bsd/wpa/dist/hostapd/hostapd_cli.c Wed Jan 20 17:03:35 2016 +0000
@@ -1375,7 +1375,7 @@
}
}
- if (daemonize && os_daemonize(pid_file))
+ if (daemonize && os_daemonize(pid_file) && eloop_sock_requeue())
return -1;
if (interactive)
diff -r 96f211718804 -r 89c285e93788 external/bsd/wpa/dist/hostapd/main.c
--- a/external/bsd/wpa/dist/hostapd/main.c Wed Jan 20 15:43:05 2016 +0000
+++ b/external/bsd/wpa/dist/hostapd/main.c Wed Jan 20 17:03:35 2016 +0000
@@ -407,9 +407,16 @@
}
#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 -r 96f211718804 -r 89c285e93788 external/bsd/wpa/dist/src/utils/eloop.c
--- a/external/bsd/wpa/dist/src/utils/eloop.c Wed Jan 20 15:43:05 2016 +0000
+++ b/external/bsd/wpa/dist/src/utils/eloop.c Wed Jan 20 17:03:35 2016 +0000
@@ -169,9 +169,6 @@
__func__, strerror(errno));
return -1;
}
- eloop.readers.type = EVENT_TYPE_READ;
- eloop.writers.type = EVENT_TYPE_WRITE;
- eloop.exceptions.type = EVENT_TYPE_EXCEPTION;
#endif /* CONFIG_ELOOP_EPOLL */
#ifdef CONFIG_ELOOP_KQUEUE
eloop.kqueuefd = kqueue();
@@ -181,26 +178,85 @@
return -1;
}
#endif /* CONFIG_ELOOP_KQUEUE */
+#if defined(CONFIG_ELOOP_EPOLL) || defined(CONFIG_ELOOP_KQUEUE)
+ eloop.readers.type = EVENT_TYPE_READ;
+ eloop.writers.type = EVENT_TYPE_WRITE;
+ eloop.exceptions.type = EVENT_TYPE_EXCEPTION;
+#endif
#ifdef WPA_TRACE
signal(SIGSEGV, eloop_sigsegv_handler);
#endif /* WPA_TRACE */
return 0;
}
+#ifdef CONFIG_ELOOP_EPOLL
+static int eloop_sock_queue(int sock, eloop_event_type type)
+{
+ struct epoll_event ev;
+
+ os_memset(&ev, 0, sizeof(ev));
+ switch (type) {
+ case EVENT_TYPE_READ:
+ ev.events = EPOLLIN;
+ break;
+ case EVENT_TYPE_WRITE:
+ ev.events = EPOLLOUT;
+ break;
+ /*
+ * Exceptions are always checked when using epoll, but I suppose it's
+ * possible that someone registered a socket *only* for exception
+ * handling.
+ */
+ case EVENT_TYPE_EXCEPTION:
+ ev.events = EPOLLERR | EPOLLHUP;
+ break;
+ }
+ ev.data.fd = sock;
+ if (epoll_ctl(eloop.epollfd, EPOLL_CTL_ADD, sock, &ev) < 0) {
+ wpa_printf(MSG_ERROR, "%s: epoll_ctl(ADD) for fd=%d "
+ "failed. %s\n", __func__, sock, strerror(errno));
+ return -1;
+ }
+ return 0;
+}
+#endif /* CONFIG_ELOOP_EPOLL */
+
+#ifdef CONFIG_ELOOP_KQUEUE
+static int eloop_sock_queue(int sock, eloop_event_type type)
+{
+ int filter;
+ struct kevent ke;
+
+ switch (type) {
+ case EVENT_TYPE_READ:
+ filter = EVFILT_READ;
+ break;
+ case EVENT_TYPE_WRITE:
+ filter = EVFILT_WRITE;
+ break;
+ default:
+ filter = 0;
+ }
+ EV_SET(&ke, sock, filter, EV_ADD, 0, 0, NULL);
+ if (kevent(eloop.kqueuefd, &ke, 1, NULL, 0, NULL) == -1) {
+ wpa_printf(MSG_ERROR, "%s: kevent(ADD) for fd=%d "
+ "failed. %s\n", __func__, sock, strerror(errno));
+ return -1;
+ }
+ return 0;
+}
+#endif /* CONFIG_ELOOP_KQUEUE */
static int eloop_sock_table_add_sock(struct eloop_sock_table *table,
int sock, eloop_sock_handler handler,
void *eloop_data, void *user_data)
{
#ifdef CONFIG_ELOOP_EPOLL
- struct eloop_sock *temp_table;
- struct epoll_event ev, *temp_events;
- int next;
+ struct epoll_event *temp_events;
#endif /* CONFIG_ELOOP_EPOLL */
-#ifdef CONFIG_ELOOP_KQUEUE
+#if defined(CONFIG_ELOOP_EPOLL) || defined(CONFIG_ELOOP_KQUEUE)
struct eloop_sock *temp_table;
- int next, filter;
- struct kevent ke;
+ int next;
#endif
struct eloop_sock *tmp;
int new_max_sock;
@@ -302,53 +358,12 @@
table->changed = 1;
eloop_trace_sock_add_ref(table);
-#ifdef CONFIG_ELOOP_EPOLL
- os_memset(&ev, 0, sizeof(ev));
- switch (table->type) {
- case EVENT_TYPE_READ:
- ev.events = EPOLLIN;
- break;
- case EVENT_TYPE_WRITE:
- ev.events = EPOLLOUT;
- break;
- /*
- * Exceptions are always checked when using epoll, but I suppose it's
- * possible that someone registered a socket *only* for exception
- * handling.
- */
- case EVENT_TYPE_EXCEPTION:
- ev.events = EPOLLERR | EPOLLHUP;
- break;
- }
- ev.data.fd = sock;
- if (epoll_ctl(eloop.epollfd, EPOLL_CTL_ADD, sock, &ev) < 0) {
- wpa_printf(MSG_ERROR, "%s: epoll_ctl(ADD) for fd=%d "
- "failed. %s\n", __func__, sock, strerror(errno));
+#if defined(CONFIG_ELOOP_EPOLL) || defined(CONFIG_ELOOP_KQUEUE)
+ if (eloop_sock_queue(sock, table->type) == -1)
return -1;
- }
os_memcpy(&eloop.fd_table[sock], &table->table[table->count - 1],
sizeof(struct eloop_sock));
-#endif /* CONFIG_ELOOP_EPOLL */
-#ifdef CONFIG_ELOOP_KQUEUE
- switch (table->type) {
- case EVENT_TYPE_READ:
- filter = EVFILT_READ;
- break;
- case EVENT_TYPE_WRITE:
- filter = EVFILT_WRITE;
- break;
- default:
- filter = 0;
- }
- EV_SET(&ke, sock, filter, EV_ADD, 0, 0, NULL);
- if (kevent(eloop.kqueuefd, &ke, 1, NULL, 0, NULL) == -1) {
- wpa_printf(MSG_ERROR, "%s: kevent(ADD) for fd=%d "
- "failed. %s\n", __func__, sock, strerror(errno));
- return -1;
- }
- os_memcpy(&eloop.fd_table[sock], &table->table[table->count - 1],
- sizeof(struct eloop_sock));
-#endif /* CONFIG_ELOOP_KQUEUE */
+#endif
return 0;
}
@@ -621,7 +636,48 @@
break;
}
}
-#endif /* CONFIG_ELOOP_KQUEUE */
+
+static int eloop_sock_table_requeue(struct eloop_sock_table *table)
+{
+ int i, r;
+ struct kevent ke;
+
+ r = 0;
+ for (i = 0; i < table->count && table->table; i++) {
+ if (eloop_sock_queue(table->table[i].sock, table->type) == -1)
+ r = -1;
+ }
+ return r;
+}
+
+int eloop_sock_requeue(void)
+{
+ int r = 0;
+
+ close(eloop.kqueuefd);
+ eloop.kqueuefd = kqueue();
+ if (eloop.kqueuefd < 0) {
+ wpa_printf(MSG_ERROR, "%s: kqueue failed. %s\n",
+ __func__, strerror(errno));
+ return -1;
+ }
+
+ if (eloop_sock_table_requeue(&eloop.readers) == -1)
+ r = -1;
+ if (eloop_sock_table_requeue(&eloop.writers) == -1)
+ r = -1;
+ if (eloop_sock_table_requeue(&eloop.exceptions) == -1)
+ r = -1;
+
+ return r;
+}
+#else /* CONFIG_ELOOP_KQUEUE */
+int eloop_sock_requeue(void)
+{
+
+ return 0;
+}
+#endif /* !CONFIG_ELOOP_KQUEUE */
static void eloop_sock_table_destroy(struct eloop_sock_table *table)
{
diff -r 96f211718804 -r 89c285e93788 external/bsd/wpa/dist/src/utils/eloop.h
--- a/external/bsd/wpa/dist/src/utils/eloop.h Wed Jan 20 15:43:05 2016 +0000
+++ b/external/bsd/wpa/dist/src/utils/eloop.h Wed Jan 20 17:03:35 2016 +0000
@@ -313,6 +313,14 @@
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
*
* Start the event loop and continue running as long as there are any
diff -r 96f211718804 -r 89c285e93788 external/bsd/wpa/dist/wpa_supplicant/wpa_cli.c
--- a/external/bsd/wpa/dist/wpa_supplicant/wpa_cli.c Wed Jan 20 15:43:05 2016 +0000
+++ b/external/bsd/wpa/dist/wpa_supplicant/wpa_cli.c Wed Jan 20 17:03:35 2016 +0000
@@ -4085,7 +4085,7 @@
}
}
- if (daemonize && os_daemonize(pid_file))
+ if (daemonize && os_daemonize(pid_file) && eloop_sock_requeue())
return -1;
if (action_file)
diff -r 96f211718804 -r 89c285e93788 external/bsd/wpa/dist/wpa_supplicant/wpa_supplicant.c
--- a/external/bsd/wpa/dist/wpa_supplicant/wpa_supplicant.c Wed Jan 20 15:43:05 2016 +0000
+++ b/external/bsd/wpa/dist/wpa_supplicant/wpa_supplicant.c Wed Jan 20 17:03:35 2016 +0000
@@ -4630,7 +4630,8 @@
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) {
Home |
Main Index |
Thread Index |
Old Index