]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add event/talloc_ctx binding argument
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 6 Jul 2017 02:31:21 +0000 (22:31 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 6 Jul 2017 02:31:21 +0000 (22:31 -0400)
Reorder fr_event_timer_insert arguments to be consistent with other event

src/include/event.h
src/lib/util/event.c
src/main/connection.c
src/main/process.c
src/main/radsniff.c
src/main/threads.c
src/main/unlang_interpret.c
src/modules/proto_bfd/proto_bfd.c
src/modules/proto_ldap_sync/proto_ldap_sync.c
src/modules/proto_radius/proto_radius_udp.c
src/modules/rlm_rest/io.c

index 95288277b03e2bcb40497b59ad5aa8a834eb84d4..554f0780285604ad00deb61278ffaf3dc9e4ba38 100644 (file)
@@ -99,16 +99,15 @@ int         fr_event_fd_insert(fr_event_list_t *el, int fd,
                                   fr_event_fd_handler_t read_fn,
                                   fr_event_fd_handler_t write_fn,
                                   fr_event_fd_error_handler_t error,
-                                  void *ctx);
+                                  void *uctx);
 
-int            fr_event_timer_delete(fr_event_list_t *el, fr_event_timer_t **parent);
-int            fr_event_timer_insert(fr_event_list_t *el,
-                                     fr_event_callback_t callback,
-                                     void const *ctx, struct timeval *when, fr_event_timer_t **parent);
+int            fr_event_timer_insert(TALLOC_CTX *ctx, fr_event_list_t *el, fr_event_timer_t **ev,
+                                     struct timeval *when, fr_event_callback_t callback, void const *uctx);
+int            fr_event_timer_delete(fr_event_list_t *el, fr_event_timer_t **ev);
 int            fr_event_timer_run(fr_event_list_t *el, struct timeval *when);
 
-uintptr_t              fr_event_user_insert(fr_event_list_t *el, fr_event_user_handler_t user, void *ctx) CC_HINT(nonnull(1,2));
-int            fr_event_user_delete(fr_event_list_t *el, fr_event_user_handler_t user, void *ctx) CC_HINT(nonnull(1,2));
+uintptr_t              fr_event_user_insert(fr_event_list_t *el, fr_event_user_handler_t user, void *uctx) CC_HINT(nonnull(1,2));
+int            fr_event_user_delete(fr_event_list_t *el, fr_event_user_handler_t user, void *uctx) CC_HINT(nonnull(1,2));
 
 int            fr_event_pre_insert(fr_event_list_t *el, fr_event_status_t callback, void *uctx) CC_HINT(nonnull(1,2));
 int            fr_event_pre_delete(fr_event_list_t *el, fr_event_status_t callback, void *uctx) CC_HINT(nonnull(1,2));
index f44a59e4ede65fa21f78e02c73153e5884d613f6..6446cc3d6d088c163a0ff5a44be48feaef417c3b 100644 (file)
@@ -45,9 +45,10 @@ RCSID("$Id$")
  *
  */
 struct fr_event_timer_t {
-       fr_event_callback_t     callback;               //!< Callback to execute when the timer fires.
-       void const              *ctx;                   //!< Context pointer to pass to the callback.
        struct timeval          when;                   //!< When this timer should fire.
+       fr_event_callback_t     callback;               //!< Callback to execute when the timer fires.
+       void const              *uctx;                  //!< Context pointer to pass to the callback.
+       TALLOC_CTX              *linked_ctx;            //!< talloc ctx this event was bound to.
 
        fr_event_timer_t        **parent;               //!< Previous timer.
        int                     heap;                   //!< Where to store opaque heap data.
@@ -79,7 +80,7 @@ typedef struct fr_event_fd_t {
        bool                    deferred_delete;        //!< Deferred deletion flag.  Delete this event *after*
                                                        //!< the handlers complete.
 
-       void                    *ctx;                   //!< Context pointer to pass to each file descriptor callback.
+       void                    *uctx;                  //!< Context pointer to pass to each file descriptor callback.
 } fr_event_fd_t;
 
 /** Callbacks to perform when the event handler is about to check the events.
@@ -88,7 +89,7 @@ typedef struct fr_event_fd_t {
 typedef struct fr_event_pre_t {
        fr_dlist_t              entry;                  //!< linked list of callback
        fr_event_status_t       callback;               //!< the callback to call
-       void                    *ctx;                   //!< context for the callback.
+       void                    *uctx;                  //!< context for the callback.
 } fr_event_pre_t;
 
 
@@ -98,7 +99,7 @@ typedef struct fr_event_pre_t {
 typedef struct fr_event_post_t {
        fr_dlist_t              entry;                  //!< linked list of callback
        fr_event_callback_t     callback;               //!< the callback to call
-       void                    *ctx;                   //!< context for the callback.
+       void                    *uctx;                  //!< context for the callback.
 } fr_event_post_t;
 
 
@@ -109,7 +110,7 @@ typedef struct fr_event_user_t {
        fr_dlist_t              entry;                  //!< linked list of callback
        uintptr_t               ident;                  //!< the identifier of this event
        fr_event_user_handler_t callback;               //!< the callback to call
-       void                    *ctx;                   //!< context for the callback.
+       void                    *uctx;                  //!< context for the callback.
 } fr_event_user_t;
 
 
@@ -319,7 +320,7 @@ static int _fr_event_fd_free(fr_event_fd_t *ef)
  * @param[in] read_fn  function to call when fd is readable.
  * @param[in] write_fn function to call when fd is writable.
  * @param[in] error    function to call when an error occurs on the fd.
- * @param[in] ctx      to pass to handler.
+ * @param[in] uctx     to pass to handler.
  * @return
  *     - 0 on succes.
  *     - -1 on failure.
@@ -328,7 +329,7 @@ int fr_event_fd_insert(fr_event_list_t *el, int fd,
                       fr_event_fd_handler_t read_fn,
                       fr_event_fd_handler_t write_fn,
                       fr_event_fd_error_handler_t error,
-                      void *ctx)
+                      void *uctx)
 {
        int             count = 0;
        struct kevent   evset[2];
@@ -412,7 +413,7 @@ int fr_event_fd_insert(fr_event_list_t *el, int fd,
                        return -1;
                }
 
-               ef->ctx = ctx;
+               ef->uctx = uctx;
                ef->read = read_fn;
                ef->write = write_fn;
                ef->error = error;
@@ -449,7 +450,7 @@ int fr_event_fd_insert(fr_event_list_t *el, int fd,
         *      deferred_delete flag.
         */
        ef->deferred_delete = false;
-       ef->ctx = ctx;
+       ef->uctx = uctx;
        ef->read = read_fn;
        ef->write = write_fn;
        ef->error = error;
@@ -461,38 +462,36 @@ int fr_event_fd_insert(fr_event_list_t *el, int fd,
 /** Delete a timer event from the event list
  *
  * @param[in] el       to delete event from.
- * @param[in] parent   of the event being deleted.
+ * @param[in] ev_p     of the event being deleted.
+ * @return
+ *     - 0 on success.
+ *     - -1 on failure.
  */
-int fr_event_timer_delete(fr_event_list_t *el, fr_event_timer_t **parent)
+int fr_event_timer_delete(fr_event_list_t *el, fr_event_timer_t **ev_p)
 {
        int ret;
 
-       fr_event_timer_t *ev;
+       if (!*ev_p) return 0;
 
-       if (!el) {
-               fr_strerror_printf("Invalid argument: NULL event list");
-               return -1;
-       }
+       rad_assert(talloc_parent(*ev_p) == el);
 
-       if (!parent) {
-               fr_strerror_printf("Invalid arguments: NULL event pointer");
-               return -1;
-       }
+       ret = talloc_free(*ev_p);
+       if (ret == 0) *ev_p = NULL;
 
-       if (!*parent) {
-               fr_strerror_printf("Invalid arguments: NULL event");
-               return -1;
-       }
+       return ret;
+}
 
-       /*
-        *  Validate the event_t struct to detect memory issues early.
-        */
-       ev = talloc_get_type_abort(*parent, fr_event_timer_t);
-       if (ev->parent) {
-               (void)fr_cond_assert(*(ev->parent) == ev);
-               *ev->parent = NULL;
-       }
-       *parent = NULL;
+/** Remove an event from the event loop
+ *
+ * @param[in] ev       to free.
+ * @return
+ *     - 0 on success.
+ *     - -1 on failure.
+ */
+static int _event_timer_free(fr_event_timer_t *ev)
+{
+       int             ret;
+       fr_event_list_t *el = talloc_parent(ev);
 
        ret = fr_heap_extract(el->times, ev);
 
@@ -501,28 +500,27 @@ int fr_event_timer_delete(fr_event_list_t *el, fr_event_timer_t **parent)
         */
        if (!fr_cond_assert(ret == 1)) {
                fr_strerror_printf("Event not found in heap");
-               talloc_free(ev);
                return -1;
        }
-       talloc_free(ev);
 
-       return ret;
+       return 0;
 }
 
 /** Insert a timer event into an event list
  *
- * @param[in] el       to insert event into.
- * @param[in] callback function to execute if the event fires.
- * @param[in] ctx      for callback function.
- * @param[in] when     we should run the event.
- * @param[in] parent   If not NULL modify this event instead of creating a new one.  This is a parent
- *                     in a temporal sense, not in a memory structure or dependency sense.
+ * @param[in] ctx              to bind lifetime of the event to.
+ * @param[in] el               to insert event into.
+ * @param[in,out] ev_p         If not NULL modify this event instead of creating a new one.  This is a parent
+ *                             in a temporal sense, not in a memory structure or dependency sense.
+ * @param[in] when             we should run the event.
+ * @param[in] callback         function to execute if the event fires.
+ * @param[in] uctx             user data to pass to the event.
  * @return
  *     - 0 on success.
  *     - -1 on failure.
  */
-int fr_event_timer_insert(fr_event_list_t *el, fr_event_callback_t callback, void const *ctx,
-                         struct timeval *when, fr_event_timer_t **parent)
+int fr_event_timer_insert(TALLOC_CTX *ctx, fr_event_list_t *el, fr_event_timer_t **ev_p,
+                         struct timeval *when, fr_event_callback_t callback, void const *uctx)
 {
        fr_event_timer_t *ev;
 
@@ -541,8 +539,8 @@ int fr_event_timer_insert(fr_event_list_t *el, fr_event_callback_t callback, voi
                return -1;
        }
 
-       if (!parent) {
-               fr_strerror_printf("Invalid arguments: NULL parent");
+       if (!ev_p) {
+               fr_strerror_printf("Invalid arguments: NULL ev_p");
                return -1;
        }
 
@@ -555,24 +553,46 @@ int fr_event_timer_insert(fr_event_list_t *el, fr_event_callback_t callback, voi
         *      If there is an event, re-use it instead of freeing it
         *      and allocating a new one.
         */
-       if (*parent) {
+       if (!*ev_p) {
+       new_event:
+               ev = talloc_zero(el, fr_event_timer_t);
+               if (!ev) return -1;
+
+               /*
+                *      Bind the lifetime of the event to the specified
+                *      talloc ctx.  If the talloc ctx is freed, the
+                *      event will also be freed.
+                */
+               if (ctx) fr_talloc_link_ctx(ctx, ev);
+
+               talloc_set_destructor(ev, _event_timer_free);
+       } else {
                int ret;
 
-               ev = talloc_get_type_abort(*parent, fr_event_timer_t);
+               ev = talloc_get_type_abort(*ev_p, fr_event_timer_t);
+
+               /*
+                *      We can't disarm the linking context due to
+                *      limitations in talloc, so if the linking
+                *      context changes, we need to free the old
+                *      event, and allocate a new one.
+                *
+                *      Freeing the event also removes it from the heap.
+                */
+               if (ev->linked_ctx != ctx) {
+                       talloc_free(ev);
+                       goto new_event;
+               }
 
                ret = fr_heap_extract(el->times, ev);
                if (!fr_cond_assert(ret == 1)) return -1;       /* events MUST be in the heap */
-
-               memset(ev, 0, sizeof(*ev));
-       } else {
-               ev = talloc_zero(el, fr_event_timer_t);
-               if (!ev) return -1;
        }
 
-       ev->callback = callback;
-       ev->ctx = ctx;
        ev->when = *when;
-       ev->parent = parent;
+       ev->callback = callback;
+       ev->uctx = uctx;
+       ev->linked_ctx = ctx;
+       ev->parent = ev_p;
 
        if (!fr_heap_insert(el->times, ev)) {
                fr_strerror_printf("Failed inserting event into heap");
@@ -580,7 +600,7 @@ int fr_event_timer_insert(fr_event_list_t *el, fr_event_callback_t callback, voi
                return -1;
        }
 
-       *parent = ev;
+       *ev_p = ev;
 
        return 0;
 }
@@ -601,7 +621,7 @@ uintptr_t fr_event_user_insert(fr_event_list_t *el, fr_event_user_handler_t call
 
        user = talloc(el, fr_event_user_t);
        user->callback = callback;
-       user->ctx = uctx;
+       user->uctx = uctx;
        user->ident = (uintptr_t) user;
 
        fr_dlist_insert_tail(&el->user_callbacks, &user->entry);
@@ -632,7 +652,7 @@ int fr_event_user_delete(fr_event_list_t *el, fr_event_user_handler_t callback,
 
                user = fr_ptr_to_type(fr_event_user_t, entry, entry);
                if ((user->callback == callback) &&
-                   (user->ctx == uctx)) {
+                   (user->uctx == uctx)) {
                        fr_dlist_remove(entry);
                        talloc_free(user);
                        return 0;
@@ -642,7 +662,6 @@ int fr_event_user_delete(fr_event_list_t *el, fr_event_user_handler_t callback,
        return -1;
 }
 
-
 /** Add a pre-event callback to the event list.
  *
  *  Events are serviced in insert order.  i.e. insert A, B, we then
@@ -661,14 +680,13 @@ int fr_event_pre_insert(fr_event_list_t *el, fr_event_status_t callback, void *u
 
        pre = talloc(el, fr_event_pre_t);
        pre->callback = callback;
-       pre->ctx = uctx;
+       pre->uctx = uctx;
 
        fr_dlist_insert_tail(&el->pre_callbacks, &pre->entry);
 
        return 0;
 }
 
-
 /** Delete a pre-event callback from the event list.
  *
  * @param[in] el       containing the timer events.
@@ -691,7 +709,7 @@ int fr_event_pre_delete(fr_event_list_t *el, fr_event_status_t callback, void *u
 
                pre = fr_ptr_to_type(fr_event_pre_t, entry, entry);
                if ((pre->callback == callback) &&
-                   (pre->ctx == uctx)) {
+                   (pre->uctx == uctx)) {
                        fr_dlist_remove(entry);
                        talloc_free(pre);
                        return 0;
@@ -701,7 +719,6 @@ int fr_event_pre_delete(fr_event_list_t *el, fr_event_status_t callback, void *u
        return -1;
 }
 
-
 /** Add a post-event callback to the event list.
  *
  *  Events are serviced in insert order.  i.e. insert A, B, we then
@@ -720,14 +737,13 @@ int fr_event_post_insert(fr_event_list_t *el, fr_event_callback_t callback, void
 
        post = talloc(el, fr_event_post_t);
        post->callback = callback;
-       post->ctx = uctx;
+       post->uctx = uctx;
 
        fr_dlist_insert_tail(&el->post_callbacks, &post->entry);
 
        return 0;
 }
 
-
 /** Delete a post-event callback from the event list.
  *
  * @param[in] el       containing the timer events.
@@ -750,7 +766,7 @@ int fr_event_post_delete(fr_event_list_t *el, fr_event_callback_t callback, void
 
                post = fr_ptr_to_type(fr_event_post_t, entry, entry);
                if ((post->callback == callback) &&
-                   (post->ctx == uctx)) {
+                   (post->uctx == uctx)) {
                        fr_dlist_remove(entry);
                        talloc_free(post);
                        return 0;
@@ -760,7 +776,6 @@ int fr_event_post_delete(fr_event_list_t *el, fr_event_callback_t callback, void
        return -1;
 }
 
-
 /** Run a single scheduled timer event
  *
  * @param[in] el       containing the timer events.
@@ -772,7 +787,7 @@ int fr_event_post_delete(fr_event_list_t *el, fr_event_callback_t callback, void
 int fr_event_timer_run(fr_event_list_t *el, struct timeval *when)
 {
        fr_event_callback_t callback;
-       void *ctx;
+       void *uctx;
        fr_event_timer_t *ev;
 
        if (!el) return 0;
@@ -801,14 +816,14 @@ int fr_event_timer_run(fr_event_list_t *el, struct timeval *when)
        }
 
        callback = ev->callback;
-       memcpy(&ctx, &ev->ctx, sizeof(ctx));
+       memcpy(&uctx, &ev->uctx, sizeof(uctx));
 
        /*
         *      Delete the event before calling it.
         */
        fr_event_timer_delete(el, ev->parent);
 
-       callback(el, when, ctx);
+       callback(el, when, uctx);
 
        return 1;
 }
@@ -876,7 +891,7 @@ int fr_event_corral(fr_event_list_t *el, bool wait)
                fr_event_pre_t *pre;
 
                pre = fr_ptr_to_type(fr_event_pre_t, entry, entry);
-               if (pre->callback(pre->ctx, wake) > 0) {
+               if (pre->callback(pre->uctx, wake) > 0) {
                        wake = &when;
                        when.tv_sec = 0;
                        when.tv_usec = 0;
@@ -949,7 +964,7 @@ void fr_event_service(fr_event_list_t *el)
                        (void) talloc_get_type_abort(user, fr_event_user_t);
                        rad_assert(user->ident == el->events[i].ident);
 
-                       user->callback(el->kq, &el->events[i], user->ctx);
+                       user->callback(el->kq, &el->events[i], user->uctx);
                        continue;
                }
 
@@ -964,7 +979,7 @@ void fr_event_service(fr_event_list_t *el)
                          *      Call the error handler which should
                          *      tear down the connection.
                          */
-                        if (ev->error) ev->error(el, ev->fd, flags, fd_errno, ev->ctx);
+                        if (ev->error) ev->error(el, ev->fd, flags, fd_errno, ev->uctx);
                         fr_event_fd_delete(el, ev->fd);
                         continue;
                 }
@@ -1005,10 +1020,10 @@ void fr_event_service(fr_event_list_t *el)
 service:
                ev->in_handler = true;
                if (ev->read && (el->events[i].filter == EVFILT_READ)) {
-                       ev->read(el, ev->fd, flags, ev->ctx);
+                       ev->read(el, ev->fd, flags, ev->uctx);
                }
                if (ev->write && (el->events[i].filter == EVFILT_WRITE) && !ev->deferred_delete) {
-                       ev->write(el, ev->fd, flags, ev->ctx);
+                       ev->write(el, ev->fd, flags, ev->uctx);
                }
                ev->in_handler = false;
 
@@ -1041,7 +1056,7 @@ service:
                when = el->now;
 
                post = fr_ptr_to_type(fr_event_post_t, entry, entry);
-               post->callback(el, &when, post->ctx);
+               post->callback(el, &when, post->uctx);
        }
 }
 
@@ -1122,14 +1137,14 @@ static int _event_list_free(fr_event_list_t *el)
 
 /** Initialise a new event list
  *
- * @param[in] ctx      to allocate memory in.
- * @param[in] status   callback, called on each iteration of the event list.
- * @param[in] status_ctx context for the status callback
+ * @param[in] ctx              to allocate memory in.
+ * @param[in] status           callback, called on each iteration of the event list.
+ * @param[in] status_uctx      context for the status callback
  * @return
  *     - A pointer to a new event list on success (free with talloc_free).
  *     - NULL on error.
  */
-fr_event_list_t *fr_event_list_alloc(TALLOC_CTX *ctx, fr_event_status_t status, void *status_ctx)
+fr_event_list_t *fr_event_list_alloc(TALLOC_CTX *ctx, fr_event_status_t status, void *status_uctx)
 {
        fr_event_list_t *el;
        struct kevent kev;
@@ -1157,7 +1172,7 @@ fr_event_list_t *fr_event_list_alloc(TALLOC_CTX *ctx, fr_event_status_t status,
        FR_DLIST_INIT(el->post_callbacks);
        FR_DLIST_INIT(el->user_callbacks);
 
-       if (status) (void) fr_event_pre_insert(el, status, status_ctx);
+       if (status) (void) fr_event_pre_insert(el, status, status_uctx);
 
        /*
         *      Set our "exit" callback as ident 0.
@@ -1238,7 +1253,7 @@ int main(int argc, char **argv)
                        array[i].tv_usec -= 1000000;
                        array[i].tv_sec++;
                }
-               fr_event_timer_insert(el, print_time, &array[i], &array[i]);
+               fr_event_timer_insert(NULL, el, &array[i], print_time, &array[i]);
        }
 
        while (fr_event_list_num_elements(el)) {
index 16fd792ebbbc3fa5c60378d92717174159c9f916..c7d4175fb92c1a3f9f93ab3c2f9314fedcb42921 100644 (file)
@@ -127,7 +127,8 @@ static void connection_state_failed(fr_connection_t *conn, struct timeval *now)
                struct timeval when;
 
                fr_timeval_add(&when, now, &conn->reconnection_delay);
-               fr_event_timer_insert(conn->el, _reconnect_delay_done, conn, &when, &conn->reconnection_timer);
+               fr_event_timer_insert(conn, conn->el, &conn->reconnection_timer,
+                                     &when, _reconnect_delay_done, conn);
        }
                break;
 
@@ -257,7 +258,8 @@ static void connection_state_init(fr_connection_t *conn, struct timeval *now)
                        connection_state_failed(conn, now);
                        return;
                }
-               fr_event_timer_insert(conn->el, _connection_timeout, conn, &when, &conn->connection_timer);
+               fr_event_timer_insert(conn, conn->el, &conn->connection_timer,
+                                     &when, _connection_timeout, conn);
                conn->fd = fd;
        }
                break;
index 8e14fe73e29b94247ae6838d1463cb95e45ff5e6..159b3697ca622568ccc224492b23298da2f4d58b 100644 (file)
@@ -218,7 +218,8 @@ static void sd_watchdog_event(fr_event_list_t *our_el, struct timeval *now, void
        sd_notify(0, "WATCHDOG=1");
 
        fr_timeval_add(&when, &sd_watchdog_interval, now);
-       if (fr_event_timer_insert(our_el, sd_watchdog_event, ctx, &when, &sd_watchdog_ev) < 0) {
+       if (fr_event_timer_insert(NULL, our_el, &sd_watchdog_ev,
+                                 &when, sd_watchdog_event, ctx) < 0) {
                rad_panic("Failed to insert watchdog event");
        }
 }
index 7da55810b6e0384538a83ed1daf63136a0c4f430..4d669c32d9d914c42e7c5227638ce19ffd51dc58 100644 (file)
@@ -850,7 +850,8 @@ clear:
                now->tv_sec += conf->stats.interval;
                now->tv_usec = 0;
 
-               if (fr_event_timer_insert(el, rs_stats_process, ctx, now, &event) < 0) {
+               if (fr_event_timer_insert(NULL, el, &event,
+                                         now, rs_stats_process, ctx) < 0) {
                        ERROR("Failed inserting stats interval event");
                }
        }
@@ -919,7 +920,8 @@ static int rs_install_stats_processor(rs_stats_t *stats, fr_event_list_t *el,
                rs_tv_add_ms(now, conf->stats.timeout, &(stats->quiet));
        }
 
-       if (fr_event_timer_insert(events, rs_stats_process, (void *) &update, now, &event) < 0) {
+       if (fr_event_timer_insert(NULL, events, (void *) &update,
+                                 now, rs_stats_process, &event) < 0) {
                ERROR("Failed inserting stats event");
                return -1;
        }
@@ -1439,7 +1441,8 @@ static void rs_packet_process(uint64_t count, rs_event_t *event, struct pcap_pkt
                         */
                        original->linked = talloc_steal(original, current);
                        rs_tv_add_ms(&header->ts, conf->stats.timeout, &original->when);
-                       if (fr_event_timer_insert(event->list, _rs_event, original, &original->when, &original->event) < 0) {
+                       if (fr_event_timer_insert(NULL, event->list, &original->event,
+                                                 &original->when, _rs_event, original) < 0) {
                                REDEBUG("Failed inserting new event");
                                /*
                                 *      Delete the original request/event, it's no longer valid
@@ -1669,8 +1672,8 @@ static void rs_packet_process(uint64_t count, rs_event_t *event, struct pcap_pkt
                 */
                original->packet->timestamp = header->ts;
                rs_tv_add_ms(&header->ts, conf->stats.timeout, &original->when);
-               if (fr_event_timer_insert(event->list, _rs_event, original,
-                                         &original->when, &original->event) < 0) {
+               if (fr_event_timer_insert(NULL, event->list, &original->event,
+                                         &original->when, _rs_event, original) < 0) {
                        REDEBUG("Failed inserting new event");
 
                        talloc_free(original);
@@ -2013,7 +2016,8 @@ static void rs_collectd_reopen(fr_event_list_t *el, struct timeval *now, UNUSED
        ERROR("Will attempt to re-establish connection in %i ms", RS_SOCKET_REOPEN_DELAY);
 
        rs_tv_add_ms(now, RS_SOCKET_REOPEN_DELAY, &when);
-       if (fr_event_timer_insert(el, rs_collectd_reopen, el, &when, &event) < 0) {
+       if (fr_event_timer_insert(NULL, el, &event,
+                                 &when, rs_collectd_reopen, el) < 0) {
                ERROR("Failed inserting re-open event");
                RS_ASSERT(0);
        }
index 54f85e2ceecd9212c3bf931d87abef84bffe659d..2bb156d45b55b540332eeb2f9b370eefdb76fa2f 100644 (file)
@@ -528,8 +528,8 @@ static void *thread_handler(void *arg)
                                request->thread_ctx = NULL;
 
                                request->el = el;
-                               if (fr_event_timer_insert(request->el, max_request_time_hook,
-                                                         request, &when, &request->ev) < 0) {
+                               if (fr_event_timer_insert(request, request->el, &request->ev,
+                                                         &when, max_request_time_hook, request) < 0) {
                                        REDEBUG("Failed inserting max_request_time");
                                }
                        }
index 51aaa654cd262904b0d93782a4ed456db061cdcd..ddfd8b1edbb605b130b1dcee449e2574a5ece7ea 100644 (file)
@@ -1842,7 +1842,8 @@ int unlang_event_timeout_add(REQUEST *request, fr_unlang_timeout_callback_t call
        ev->thread = modcall_state->thread;
        ev->ctx = ctx;
 
-       if (fr_event_timer_insert(request->el, unlang_event_timeout_handler, ev, when, &(ev->ev)) < 0) {
+       if (fr_event_timer_insert(request, request->el, &ev->ev,
+                                 when, unlang_event_timeout_handler, ev) < 0) {
                RPEDEBUG("Failed inserting event");
                talloc_free(ev);
                return -1;
index 0a8f01e9c732d011db9673a1c188d004da822e0a..eba5ce966b8c8ab82f29c67bb213c5ad7a4bec0c 100644 (file)
@@ -924,8 +924,8 @@ static int bfd_start_packets(bfd_state_t *session)
                now.tv_usec -= USEC;
        }
 
-       if (fr_event_timer_insert(session->el, bfd_send_packet, session, &now,
-                           &session->ev_packet) < 0) {
+       if (fr_event_timer_insert(session, session->el, &session->ev_packet,
+                                 &now, bfd_send_packet, session) < 0) {
                rad_assert("Failed to insert event" == NULL);
        }
 
@@ -965,8 +965,8 @@ static void bfd_set_timeout(bfd_state_t *session, struct timeval *when)
                }
        }
 
-       if (fr_event_timer_insert(session->el, bfd_detection_timeout, session, &now,
-                            &session->ev_timeout) < 0) {
+       if (fr_event_timer_insert(session, session->el, &session->ev_timeout,
+                                 &now, bfd_detection_timeout, session) < 0) {
                rad_assert("Failed to insert event" == NULL);
        }
 }
index b0e353a3c045fc501a43f4c900e90af4f9721ac9..03d4b28d6c3154912ef309e27bc7621b83364f6c 100644 (file)
@@ -530,7 +530,8 @@ static void proto_ldap_sync_reinit(fr_event_list_t *el, struct timeval *now, voi
        PERROR("Failed reinitialising sync, will retry in %pT seconds", &inst->sync_retry_interval);
 
        fr_timeval_add(&when, now, &inst->sync_retry_interval);
-       if (fr_event_timer_insert(el, proto_ldap_sync_reinit, user_ctx, &when, &inst->sync_retry_ev) < 0) {
+       if (fr_event_timer_insert(inst, el, &inst->sync_retry_ev,
+                                 &when, proto_ldap_sync_reinit, user_ctx) < 0) {
                radlog_fatal("Failed inserting event: %s", fr_strerror());
        }
 }
@@ -885,7 +886,8 @@ static int proto_ldap_socket_recv(rad_listen_t *listen)
                memcpy(&ctx, &config, sizeof(ctx));
                gettimeofday(&now, 0);
                fr_timeval_add(&when, &now, &inst->sync_retry_interval);
-               if (fr_event_timer_insert(inst->el, proto_ldap_sync_reinit, ctx, &when, &inst->sync_retry_ev) < 0) {
+               if (fr_event_timer_insert(inst, inst->el, &inst->sync_retry_ev,
+                                         &when, proto_ldap_sync_reinit, ctx) < 0) {
                        radlog_fatal("Failed inserting event: %s", fr_strerror());
                }
                return 1;
@@ -899,7 +901,8 @@ static int proto_ldap_socket_recv(rad_listen_t *listen)
                memcpy(&ctx, &config, sizeof(ctx));
                gettimeofday(&now, 0);
                fr_timeval_add(&when, &now, &inst->conn_retry_interval);
-               if (fr_event_timer_insert(inst->el, proto_ldap_conn_init, listen, &when, &inst->conn_retry_ev) < 0) {
+               if (fr_event_timer_insert(inst, inst->el, &inst->conn_retry_ev,
+                                         &when, proto_ldap_conn_init, listen) < 0) {
                        radlog_fatal("Failed inserting event: %s", fr_strerror());
                }
 
@@ -961,8 +964,8 @@ static int proto_ldap_socket_open(UNUSED CONF_SECTION *cs, rad_listen_t *listen)
 
                        fr_timeval_add(&when, &now, &inst->conn_retry_interval);
 
-                       if (fr_event_timer_insert(inst->el, proto_ldap_conn_init,
-                                                 listen, &when, &inst->conn_retry_ev) < 0) {
+                       if (fr_event_timer_insert(inst, inst->el, &inst->conn_retry_ev,
+                                                 &when, proto_ldap_conn_init, listen) < 0) {
                                radlog_fatal("Failed inserting event: %s", fr_strerror());
                        }
 
index 32390cdf21d0adbdd12878d5ce761de126e61428..414f1994b3a15b3fb91331a541677af90e129de7 100644 (file)
@@ -239,7 +239,8 @@ static ssize_t mod_read(void const *instance, void **packet_ctx, fr_time_t **rec
                        gettimeofday(&tv, NULL);
                        tv.tv_sec += inst->cleanup_delay;
 
-                       (void) fr_event_timer_insert(inst->el, mod_cleanup_delay, track, &tv, &track->ev);
+                       (void) fr_event_timer_insert(NULL, inst->el, &track->ev,
+                                                    &tv, mod_cleanup_delay, track);
                }
 
                /*
@@ -337,7 +338,8 @@ static ssize_t mod_write(void const *instance, void *packet_ctx,
         /*
          *     Clean up after a while.
          */
-        if (fr_event_timer_insert(inst->el, mod_cleanup_delay, track, &tv, &track->ev) < 0) {
+        if (fr_event_timer_insert(NULL, inst->el, &track->ev,
+                                  &tv, mod_cleanup_delay, track) < 0) {
                (void) fr_radius_tracking_entry_delete(inst->ft, track);
                return data_size;
         }
index 20dcc8cbccb01a800dca16c611ba44db65fddef7..bb1a44d1f68b4216669241794cbded3e03c925d6 100644 (file)
@@ -238,7 +238,8 @@ static int _rest_io_timer_modify(CURLM *mandle, long timeout_ms, void *ctx)
        fr_timeval_from_ms(&to_add, (uint64_t)timeout_ms);
        fr_timeval_add(&when, &now, &to_add);
 
-       (void) fr_event_timer_insert(t->el, _rest_io_timer_expired, t, &when, &t->ev);
+       (void) fr_event_timer_insert(NULL, t->el, &t->ev,
+                                    &when, _rest_io_timer_expired, t);
 
        return 0;
 }