]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
event: Pass back opaque pointer for fd event
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 30 Apr 2020 16:50:55 +0000 (11:50 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 30 Apr 2020 17:08:10 +0000 (12:08 -0500)
src/lib/io/network.c
src/lib/util/event.c
src/lib/util/event.h
src/modules/proto_detail/proto_detail_file.c
src/modules/proto_detail/proto_detail_work.c

index 78e465b868bd563e2ae77f06c5eec4f0a762440c..01e46ffbd9f43623d29931a06f2fb66250e91e7f 100644 (file)
@@ -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) {
index 4ef69b27892a0e86d6a1481948a7464eb8cd0ce7..db602649a15986d9be55a75005c69a7d8b3f661b 100644 (file)
@@ -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
index 1571a3543a3dc53dbd1aa6d074d7a90a0b6f13c6..1cdc13557bfcaa87a7bd6288fcf5f61320d4f84f 100644 (file)
@@ -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,
index c1d7da4ff10e73b72089af6061ed4dc1be8b7fd4..b8659597d8042ea78b338f278c205164a2c7f6b5 100644 (file)
@@ -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);
index ab064e935e16b655f8de56e7603f2d04942b38f8..e4c06ba5fe36200d8de7ac1ee27d9c8f8eaa810d 100644 (file)
@@ -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