Skip to content

Commit

Permalink
tevent: split out a tevent_common_fd_disarm() helper
Browse files Browse the repository at this point in the history
It means tevent_trace_fd_callback(TEVENT_EVENT_TRACE_DETACH)
is always called and similar future changes are only
needed in one place.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
  • Loading branch information
metze-samba authored and slowfranklin committed Oct 13, 2023
1 parent 7672a29 commit 95d6600
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 37 deletions.
5 changes: 1 addition & 4 deletions lib/tevent/tevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,7 @@ int tevent_common_context_destructor(struct tevent_context *ev)

for (fd = ev->fd_events; fd; fd = fn) {
fn = fd->next;
tevent_trace_fd_callback(fd->event_ctx, fd, TEVENT_EVENT_TRACE_DETACH);
fd->wrapper = NULL;
fd->event_ctx = NULL;
DLIST_REMOVE(ev->fd_events, fd);
tevent_common_fd_disarm(fd);
}

ev->last_zero_timer = NULL;
Expand Down
32 changes: 8 additions & 24 deletions lib/tevent/tevent_epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,8 @@ static int epoll_add_multiplex_fd(struct epoll_event_context *epoll_ev,
"EPOLL_CTL_MOD EBADF for "
"add_fde[%p] mpx_fde[%p] fd[%d] - disabling\n",
add_fde, mpx_fde, add_fde->fd);
DLIST_REMOVE(epoll_ev->ev->fd_events, mpx_fde);
mpx_fde->wrapper = NULL;
mpx_fde->event_ctx = NULL;
DLIST_REMOVE(epoll_ev->ev->fd_events, add_fde);
add_fde->wrapper = NULL;
add_fde->event_ctx = NULL;
tevent_common_fd_disarm(mpx_fde);
tevent_common_fd_disarm(add_fde);
return 0;
} else if (ret != 0) {
return ret;
Expand Down Expand Up @@ -382,13 +378,9 @@ static void epoll_add_event(struct epoll_event_context *epoll_ev, struct tevent_
"EPOLL_CTL_ADD EBADF for "
"fde[%p] mpx_fde[%p] fd[%d] - disabling\n",
fde, mpx_fde, fde->fd);
DLIST_REMOVE(epoll_ev->ev->fd_events, fde);
fde->wrapper = NULL;
fde->event_ctx = NULL;
tevent_common_fd_disarm(fde);
if (mpx_fde != NULL) {
DLIST_REMOVE(epoll_ev->ev->fd_events, mpx_fde);
mpx_fde->wrapper = NULL;
mpx_fde->event_ctx = NULL;
tevent_common_fd_disarm(mpx_fde);
}
return;
} else if (ret != 0 && errno == EEXIST && mpx_fde == NULL) {
Expand Down Expand Up @@ -459,13 +451,9 @@ static void epoll_del_event(struct epoll_event_context *epoll_ev, struct tevent_
"EPOLL_CTL_DEL EBADF for "
"fde[%p] mpx_fde[%p] fd[%d] - disabling\n",
fde, mpx_fde, fde->fd);
DLIST_REMOVE(epoll_ev->ev->fd_events, fde);
fde->wrapper = NULL;
fde->event_ctx = NULL;
tevent_common_fd_disarm(fde);
if (mpx_fde != NULL) {
DLIST_REMOVE(epoll_ev->ev->fd_events, mpx_fde);
mpx_fde->wrapper = NULL;
mpx_fde->event_ctx = NULL;
tevent_common_fd_disarm(mpx_fde);
}
return;
} else if (ret != 0) {
Expand Down Expand Up @@ -510,13 +498,9 @@ static void epoll_mod_event(struct epoll_event_context *epoll_ev, struct tevent_
"EPOLL_CTL_MOD EBADF for "
"fde[%p] mpx_fde[%p] fd[%d] - disabling\n",
fde, mpx_fde, fde->fd);
DLIST_REMOVE(epoll_ev->ev->fd_events, fde);
fde->wrapper = NULL;
fde->event_ctx = NULL;
tevent_common_fd_disarm(fde);
if (mpx_fde != NULL) {
DLIST_REMOVE(epoll_ev->ev->fd_events, mpx_fde);
mpx_fde->wrapper = NULL;
mpx_fde->event_ctx = NULL;
tevent_common_fd_disarm(mpx_fde);
}
return;
} else if (ret != 0) {
Expand Down
13 changes: 13 additions & 0 deletions lib/tevent/tevent_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -561,3 +561,16 @@ void tevent_trace_immediate_callback(struct tevent_context *ev,
void tevent_trace_queue_callback(struct tevent_context *ev,
struct tevent_queue_entry *qe,
enum tevent_event_trace_point);

#include "tevent_dlinklist.h"

static inline void tevent_common_fd_disarm(struct tevent_fd *fde)
{
if (fde->event_ctx != NULL) {
tevent_trace_fd_callback(fde->event_ctx, fde,
TEVENT_EVENT_TRACE_DETACH);
DLIST_REMOVE(fde->event_ctx->fd_events, fde);
fde->event_ctx = NULL;
}
fde->wrapper = NULL;
}
8 changes: 2 additions & 6 deletions lib/tevent/tevent_poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,7 @@ static int poll_event_loop_poll(struct tevent_context *ev,
fde, pfd->fd);
poll_ev->fdes[idx] = NULL;
poll_ev->deleted = true;
DLIST_REMOVE(ev->fd_events, fde);
fde->wrapper = NULL;
fde->event_ctx = NULL;
tevent_common_fd_disarm(fde);
continue;
}

Expand Down Expand Up @@ -586,9 +584,7 @@ static int poll_event_loop_poll(struct tevent_context *ev,
poll_ev->fdes[i] = NULL;
poll_ev->deleted = true;
if (fde != NULL) {
DLIST_REMOVE(ev->fd_events, fde);
fde->wrapper = NULL;
fde->event_ctx = NULL;
tevent_common_fd_disarm(fde);
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions lib/tevent/tevent_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,7 @@ static int tevent_wrapper_context_destructor(struct tevent_context *wrap_ev)

tevent_fd_set_flags(fd, 0);

fd->wrapper = NULL;
fd->event_ctx = NULL;
DLIST_REMOVE(main_ev->fd_events, fd);
tevent_common_fd_disarm(fd);
}

for (te = main_ev->timer_events; te; te = tn) {
Expand Down

0 comments on commit 95d6600

Please sign in to comment.