From: Arran Cudbard-Bell Date: Thu, 30 Apr 2020 16:50:55 +0000 (-0500) Subject: event: Pass back opaque pointer for fd event X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3420f910b87490dcfdabab5d9a20b8dbfaf63b85;p=thirdparty%2Ffreeradius-server.git event: Pass back opaque pointer for fd event --- diff --git a/src/lib/io/network.c b/src/lib/io/network.c index 78e465b868b..01e46ffbd9f 100644 --- a/src/lib/io/network.c +++ b/src/lib/io/network.c @@ -1092,7 +1092,7 @@ static void fr_network_directory_callback(void *ctx, void const *data, size_t da s->filter = FR_EVENT_FILTER_VNODE; - if (fr_event_filter_insert(nr, nr->el, s->listen->fd, s->filter, + if (fr_event_filter_insert(nr, NULL, nr->el, s->listen->fd, s->filter, &funcs, app_io->error ? fr_network_error : NULL, s) < 0) { diff --git a/src/lib/util/event.c b/src/lib/util/event.c index 4ef69b27892..db602649a15 100644 --- a/src/lib/util/event.c +++ b/src/lib/util/event.c @@ -735,7 +735,8 @@ int fr_event_fd_move(fr_event_list_t *dst, fr_event_list_t *src, int fd, fr_even return -1; } - ret = fr_event_filter_insert(ef->linked_ctx, dst, ef->fd, ef->filter, &ef->active, ef->error, ef->uctx); + ret = fr_event_filter_insert(ef->linked_ctx, NULL, + dst, ef->fd, ef->filter, &ef->active, ef->error, ef->uctx); if (ret < 0) return -1; (void)fr_event_fd_delete(src, ef->fd, ef->filter); @@ -860,6 +861,7 @@ int fr_event_filter_update(fr_event_list_t *el, int fd, fr_event_filter_t filter /** Insert a filter for the specified fd * * @param[in] ctx to bind lifetime of the event to. + * @param[out] ef_out Previously allocated ef, or NULL. * @param[in] el to insert fd callback into. * @param[in] fd to install filters for. * @param[in] filter one of the #fr_event_filter_t values. @@ -868,7 +870,8 @@ int fr_event_filter_update(fr_event_list_t *el, int fd, fr_event_filter_t filter * @param[in] error function to call when an error occurs on the fd. * @param[in] uctx to pass to handler. */ -int fr_event_filter_insert(TALLOC_CTX *ctx, fr_event_list_t *el, int fd, +int fr_event_filter_insert(TALLOC_CTX *ctx, fr_event_fd_t **ef_out, + fr_event_list_t *el, int fd, fr_event_filter_t filter, void *funcs, fr_event_error_cb_t error, void *uctx) @@ -893,7 +896,12 @@ int fr_event_filter_insert(TALLOC_CTX *ctx, fr_event_list_t *el, int fd, return -1; } - ef = rbtree_finddata(el->fds, &(fr_event_fd_t){ .fd = fd, .filter = filter }); + if (!ef_out || !*ef_out) { + ef = rbtree_finddata(el->fds, &(fr_event_fd_t){ .fd = fd, .filter = filter }); + } else { + ef = *ef_out; + fr_assert((fd < 0) || (ef->fd == fd)); + } /* * Need to free the event to change the talloc link. @@ -994,6 +1002,8 @@ int fr_event_filter_insert(TALLOC_CTX *ctx, fr_event_list_t *el, int fd, ef->error = error; ef->uctx = uctx; + if (ef_out) *ef_out = ef; + return 0; } @@ -1023,7 +1033,7 @@ int fr_event_fd_insert(TALLOC_CTX *ctx, fr_event_list_t *el, int fd, return -1; } - return fr_event_filter_insert(ctx, el, fd, FR_EVENT_FILTER_IO, &funcs, error, uctx); + return fr_event_filter_insert(ctx, NULL, el, fd, FR_EVENT_FILTER_IO, &funcs, error, uctx); } #ifndef NDEBUG diff --git a/src/lib/util/event.h b/src/lib/util/event.h index 1571a3543a3..1cdc13557bf 100644 --- a/src/lib/util/event.h +++ b/src/lib/util/event.h @@ -203,7 +203,8 @@ fr_time_t fr_event_list_time(fr_event_list_t *el) CC_HINT(nonnull); int fr_event_fd_move(fr_event_list_t *dst, fr_event_list_t *src, int fd, fr_event_filter_t filter); int fr_event_fd_delete(fr_event_list_t *el, int fd, fr_event_filter_t filter); -int fr_event_filter_insert(TALLOC_CTX *ctx, fr_event_list_t *el, int fd, +int fr_event_filter_insert(TALLOC_CTX *ctx, fr_event_fd_t **ef_out, + fr_event_list_t *el, int fd, fr_event_filter_t filter, void *funcs, fr_event_error_cb_t error, diff --git a/src/modules/proto_detail/proto_detail_file.c b/src/modules/proto_detail/proto_detail_file.c index c1d7da4ff10..b8659597d80 100644 --- a/src/modules/proto_detail/proto_detail_file.c +++ b/src/modules/proto_detail/proto_detail_file.c @@ -347,7 +347,7 @@ static int work_exists(proto_detail_file_thread_t *thread, int fd) * @todo - ensure that proto_detail_work is done the file... * maybe by creating a new instance? */ - if (fr_event_filter_insert(thread, thread->el, fd, FR_EVENT_FILTER_VNODE, + if (fr_event_filter_insert(thread, NULL, thread->el, fd, FR_EVENT_FILTER_VNODE, &funcs, NULL, thread) < 0) { PERROR("Failed adding work socket to event loop"); close(fd); diff --git a/src/modules/proto_detail/proto_detail_work.c b/src/modules/proto_detail/proto_detail_work.c index ab064e935e1..e4c06ba5fe3 100644 --- a/src/modules/proto_detail/proto_detail_work.c +++ b/src/modules/proto_detail/proto_detail_work.c @@ -805,7 +805,7 @@ static void mod_event_list_set(fr_listen_t *li, fr_event_list_t *el, void *nr) memset(&funcs, 0, sizeof(funcs)); funcs.revoke = mod_revoke; - if (fr_event_filter_insert(thread, el, thread->fd, FR_EVENT_FILTER_VNODE, &funcs, NULL, thread) < 0) { + if (fr_event_filter_insert(thread, NULL, el, thread->fd, FR_EVENT_FILTER_VNODE, &funcs, NULL, thread) < 0) { WARN("Failed to add event watching for unmounted file system"); } #endif