diff options
author | Andrew Tridgell <tridge@samba.org> | 2007-05-17 02:38:07 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:52:32 -0500 |
commit | b6e64bad555e39013b8a70dff1c1172078d56d1a (patch) | |
tree | 510f8e59b8fec98ef9aefab1c01689e4b3568158 /source4/lib/events/events_epoll.c | |
parent | e9eb862dc0cb100bf2ee3de367a20587346f85aa (diff) | |
download | samba-b6e64bad555e39013b8a70dff1c1172078d56d1a.tar.gz samba-b6e64bad555e39013b8a70dff1c1172078d56d1a.tar.xz samba-b6e64bad555e39013b8a70dff1c1172078d56d1a.zip |
r22963: fixed the epoll/fork interaction in the epoll and aio backends
(This used to be commit aeca07659aa612bee0c4dd6bdbb24c799e912909)
Diffstat (limited to 'source4/lib/events/events_epoll.c')
-rw-r--r-- | source4/lib/events/events_epoll.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/source4/lib/events/events_epoll.c b/source4/lib/events/events_epoll.c index b553b6fd492..cfea8363abb 100644 --- a/source4/lib/events/events_epoll.c +++ b/source4/lib/events/events_epoll.c @@ -32,6 +32,9 @@ struct epoll_event_context { /* a pointer back to the generic event_context */ struct event_context *ev; + /* list of filedescriptor events */ + struct fd_event *fd_events; + /* number of registered fd event handlers */ int num_fd_events; @@ -45,6 +48,8 @@ struct epoll_event_context { /* when using epoll this is the handle from epoll_create */ int epoll_fd; + + pid_t pid; }; /* @@ -86,9 +91,32 @@ static int epoll_ctx_destructor(struct epoll_event_context *epoll_ev) static void epoll_init_ctx(struct epoll_event_context *epoll_ev) { epoll_ev->epoll_fd = epoll_create(64); + epoll_ev->pid = getpid(); talloc_set_destructor(epoll_ev, epoll_ctx_destructor); } +static void epoll_add_event(struct epoll_event_context *epoll_ev, struct fd_event *fde); + +/* + reopen the epoll handle when our pid changes + see http://junkcode.samba.org/ftp/unpacked/junkcode/epoll_fork.c for an + demonstration of why this is needed + */ +static void epoll_reopen(struct epoll_event_context *epoll_ev) +{ + struct fd_event *fde; + + close(epoll_ev->epoll_fd); + epoll_ev->epoll_fd = epoll_create(64); + if (epoll_ev->epoll_fd == -1) { + return; + } + epoll_ev->pid = getpid(); + for (fde=epoll_ev->fd_events;fde;fde=fde->next) { + epoll_add_event(epoll_ev, fde); + } +} + #define EPOLL_ADDITIONAL_FD_FLAG_HAS_EVENT (1<<0) #define EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR (1<<1) #define EPOLL_ADDITIONAL_FD_FLAG_GOT_ERROR (1<<2) @@ -99,8 +127,19 @@ static void epoll_init_ctx(struct epoll_event_context *epoll_ev) static void epoll_add_event(struct epoll_event_context *epoll_ev, struct fd_event *fde) { struct epoll_event event; + if (epoll_ev->epoll_fd == -1) return; + /* during an add event we need to check if our pid has changed + and re-open the epoll socket. Note that we don't need to do this + for other epoll changes */ + if (epoll_ev->pid != getpid()) { + epoll_reopen(epoll_ev); + /* the current event gets added in epoll_reopen(), so + we can return here */ + return; + } + fde->additional_flags &= ~EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR; /* if we don't want events yet, don't add an epoll_event */ @@ -126,6 +165,9 @@ static void epoll_add_event(struct epoll_event_context *epoll_ev, struct fd_even static void epoll_del_event(struct epoll_event_context *epoll_ev, struct fd_event *fde) { struct epoll_event event; + + DLIST_REMOVE(epoll_ev->fd_events, fde); + if (epoll_ev->epoll_fd == -1) return; fde->additional_flags &= ~EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR; @@ -193,6 +235,7 @@ static void epoll_change_event(struct epoll_event_context *epoll_ev, struct fd_e /* there's no epoll_event attached to the fde */ if (want_read || (want_write && !got_error)) { + DLIST_ADD(epoll_ev->fd_events, fde); epoll_add_event(epoll_ev, fde); return; } @@ -343,6 +386,7 @@ static struct fd_event *epoll_event_add_fd(struct event_context *ev, TALLOC_CTX epoll_ev->num_fd_events++; talloc_set_destructor(fde, epoll_event_fd_destructor); + DLIST_ADD(epoll_ev->fd_events, fde); epoll_add_event(epoll_ev, fde); return fde; |