From: Dwight Engen Date: Fri, 6 Dec 2013 20:36:44 +0000 (-0500) Subject: add epoll events to mainloop callback handlers X-Git-Tag: lxc-1.0.0.beta1~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84c92abdd1c59de02f446e02ff7fd3e1d70b4811;p=thirdparty%2Flxc.git add epoll events to mainloop callback handlers Adding the epoll events allows the handler to determine what events happened on the fd. Signed-off-by: Dwight Engen Acked-by: Stéphane Graber --- diff --git a/src/lxc/commands.c b/src/lxc/commands.c index 63adaf56c..ae4ff1ec4 100644 --- a/src/lxc/commands.c +++ b/src/lxc/commands.c @@ -752,7 +752,8 @@ static void lxc_cmd_fd_cleanup(int fd, struct lxc_handler *handler, process_unlock(); } -static int lxc_cmd_handler(int fd, void *data, struct lxc_epoll_descr *descr) +static int lxc_cmd_handler(int fd, uint32_t events, void *data, + struct lxc_epoll_descr *descr) { int ret; struct lxc_cmd_req req; @@ -816,7 +817,8 @@ out_close: goto out; } -static int lxc_cmd_accept(int fd, void *data, struct lxc_epoll_descr *descr) +static int lxc_cmd_accept(int fd, uint32_t events, void *data, + struct lxc_epoll_descr *descr) { int opt = 1, ret = -1, connection; diff --git a/src/lxc/console.c b/src/lxc/console.c index d854dbb66..5d91f24f5 100644 --- a/src/lxc/console.c +++ b/src/lxc/console.c @@ -109,7 +109,7 @@ void lxc_console_sigwinch(int sig) } } -static int lxc_console_cb_sigwinch_fd(int fd, void *cbdata, +static int lxc_console_cb_sigwinch_fd(int fd, uint32_t events, void *cbdata, struct lxc_epoll_descr *descr) { struct signalfd_siginfo siginfo; @@ -211,7 +211,7 @@ static void lxc_console_sigwinch_fini(struct lxc_tty_state *ts) free(ts); } -static int lxc_console_cb_con(int fd, void *data, +static int lxc_console_cb_con(int fd, uint32_t events, void *data, struct lxc_epoll_descr *descr) { struct lxc_console *console = (struct lxc_console *)data; @@ -628,7 +628,7 @@ err: -static int lxc_console_cb_tty_stdin(int fd, void *cbdata, +static int lxc_console_cb_tty_stdin(int fd, uint32_t events, void *cbdata, struct lxc_epoll_descr *descr) { struct lxc_tty_state *ts = cbdata; @@ -658,7 +658,7 @@ static int lxc_console_cb_tty_stdin(int fd, void *cbdata, return 0; } -static int lxc_console_cb_tty_master(int fd, void *cbdata, +static int lxc_console_cb_tty_master(int fd, uint32_t events, void *cbdata, struct lxc_epoll_descr *descr) { struct lxc_tty_state *ts = cbdata; diff --git a/src/lxc/lxc_monitord.c b/src/lxc/lxc_monitord.c index 11936a915..381b2d6e7 100644 --- a/src/lxc/lxc_monitord.c +++ b/src/lxc/lxc_monitord.c @@ -130,7 +130,7 @@ static void lxc_monitord_sockfd_remove(struct lxc_monitor *mon, int fd) { mon->clientfds_cnt--; } -static int lxc_monitord_sock_handler(int fd, void *data, +static int lxc_monitord_sock_handler(int fd, uint32_t events, void *data, struct lxc_epoll_descr *descr) { struct lxc_monitor *mon = data; @@ -139,7 +139,7 @@ static int lxc_monitord_sock_handler(int fd, void *data, return 0; } -static int lxc_monitord_sock_accept(int fd, void *data, +static int lxc_monitord_sock_accept(int fd, uint32_t events, void *data, struct lxc_epoll_descr *descr) { int ret,clientfd; @@ -262,7 +262,7 @@ static void lxc_monitord_delete(struct lxc_monitor *mon) mon->clientfds_cnt = 0; } -static int lxc_monitord_fifo_handler(int fd, void *data, +static int lxc_monitord_fifo_handler(int fd, uint32_t events, void *data, struct lxc_epoll_descr *descr) { int ret,i; diff --git a/src/lxc/lxcutmp.c b/src/lxc/lxcutmp.c index bfebe55f3..d4a180c6e 100644 --- a/src/lxc/lxcutmp.c +++ b/src/lxc/lxcutmp.c @@ -134,14 +134,15 @@ typedef void (*lxc_mainloop_timer_t) (void *data); static int utmp_get_runlevel(struct lxc_utmp *utmp_data); static int utmp_get_ntasks(struct lxc_handler *handler); -static int utmp_shutdown_handler(int fd, void *data, +static int utmp_shutdown_handler(int fd, uint32_t events, void *data, struct lxc_epoll_descr *descr); static int lxc_utmp_add_timer(struct lxc_epoll_descr *descr, lxc_mainloop_callback_t callback, void *data); static int lxc_utmp_del_timer(struct lxc_epoll_descr *descr, struct lxc_utmp *utmp_data); -static int utmp_handler(int fd, void *data, struct lxc_epoll_descr *descr) +static int utmp_handler(int fd, uint32_t events, void *data, + struct lxc_epoll_descr *descr) { struct inotify_event *ie; int size, ret, length; @@ -387,7 +388,7 @@ out: return -1; } -static int utmp_shutdown_handler(int fd, void *data, +static int utmp_shutdown_handler(int fd, uint32_t events, void *data, struct lxc_epoll_descr *descr) { int ntasks; diff --git a/src/lxc/mainloop.c b/src/lxc/mainloop.c index 9ba98ee0d..ec0c2525c 100644 --- a/src/lxc/mainloop.c +++ b/src/lxc/mainloop.c @@ -60,8 +60,8 @@ int lxc_mainloop(struct lxc_epoll_descr *descr, int timeout_ms) /* If the handler returns a positive value, exit the mainloop */ - if (handler->callback(handler->fd, handler->data, - descr) > 0) + if (handler->callback(handler->fd, events[i].events, + handler->data, descr) > 0) return 0; } diff --git a/src/lxc/mainloop.h b/src/lxc/mainloop.h index 217a58f32..21ef57744 100644 --- a/src/lxc/mainloop.h +++ b/src/lxc/mainloop.h @@ -24,6 +24,7 @@ #ifndef _mainloop_h #define _mainloop_h +#include #include "list.h" struct lxc_epoll_descr { @@ -31,7 +32,7 @@ struct lxc_epoll_descr { struct lxc_list handlers; }; -typedef int (*lxc_mainloop_callback_t)(int fd, void *data, +typedef int (*lxc_mainloop_callback_t)(int fd, uint32_t event, void *data, struct lxc_epoll_descr *descr); extern int lxc_mainloop(struct lxc_epoll_descr *descr, int timeout_ms); diff --git a/src/lxc/start.c b/src/lxc/start.c index 2ffd7f2ea..0727c2ce7 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -237,7 +237,7 @@ static int setup_signal_fd(sigset_t *oldmask) return fd; } -static int signal_handler(int fd, void *data, +static int signal_handler(int fd, uint32_t events, void *data, struct lxc_epoll_descr *descr) { struct signalfd_siginfo siginfo;