]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
reorder arguments to timer callbacks
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 26 Nov 2016 01:15:09 +0000 (20:15 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 26 Nov 2016 15:23:30 +0000 (10:23 -0500)
src/include/event.h
src/include/radiusd.h
src/main/command.c
src/main/process.c
src/main/radsniff.c
src/main/threads.c
src/main/unlang.c
src/modules/proto_bfd/proto_bfd.c
src/util/worker.c

index b7b14ae1f136927dd445f748b83f7afa73e9a91a..70c893c8ab8fe50ceadb857699a8eac261fa07f0 100644 (file)
@@ -32,13 +32,48 @@ RCSIDH(event_h, "$Id$")
 extern "C" {
 #endif
 
+/** An opaque file descriptor handle
+ */
 typedef struct fr_event_fd_t fr_event_fd_t;
+
+/** An opaque event list handle
+ */
 typedef struct fr_event_list_t fr_event_list_t;
+
+/** An opaque timer handle
+ */
 typedef struct fr_event_timer_t fr_event_timer_t;
 
-typedef        void (*fr_event_callback_t)(void *, struct timeval *now);
-typedef        int (*fr_event_status_t)(void *status_ctx, struct timeval *);
+/** Called when a timer event fires
+ *
+ * @param[in] now      The current time.
+ * @param[in] ctx      User ctx passed to #fr_event_timer_insert.
+ */
+typedef        void (*fr_event_callback_t)(struct timeval *now, void *ctx);
+
+/** Called after each event loop cycle
+ *
+ * Called before calling kqueue to put the thread in a sleeping state.
+ *
+ * @param[in] now      The current time.
+ * @param[in] ctx      User ctx passed to #fr_event_list_create.
+ */
+typedef        int (*fr_event_status_t)(struct timeval *now, void *ctx);
+
+/** Called when an IO event occurs on a file descriptor
+ *
+ * @param[in] el       Event list the file descriptor was inserted into.
+ * @param[in] sock     That experienced the IO event.
+ * @param[in] ctx      User ctx passed to #fr_event_fd_insert.
+ */
 typedef void (*fr_event_fd_handler_t)(fr_event_list_t *el, int sock, void *ctx);
+
+/** Called when a user kevent occurs
+ *
+ * @param[in] kq       that received the user kevent.
+ * @param[in] kev      The kevent.
+ * @param[in] ctx      User ctx passed to #fr_event_user_insert.
+ */
 typedef void (*fr_event_user_handler_t)(int kq, struct kevent const *kev, void *ctx);
 
 int            fr_event_list_num_fds(fr_event_list_t *el);
index 16ccf295081e16cc0bd71206d603e014e5347894..64107d200a9d5882259f0fdb77e550f8fd193746 100644 (file)
@@ -623,7 +623,7 @@ int radius_event_start(bool spawn_flag);
 void radius_event_free(void);
 int radius_event_process(void);
 void radius_update_listener(rad_listen_t *listener);
-void revive_home_server(void *ctx, struct timeval *now);
+void revive_home_server(struct timeval *now, void *ctx);
 void mark_home_server_dead(home_server_t *home, struct timeval *when);
 
 /* evaluate.c */
index cc1231088859574ec2989c772dbb91778490382d..499f35ce4f8031626632ce2d63ab11bd07c2708c 100644 (file)
@@ -1894,7 +1894,7 @@ static int command_set_home_server_state(rad_listen_t *listener, int argc, char
        }
 
        if (strcmp(argv[last], "alive") == 0) {
-               revive_home_server(home, NULL);
+               revive_home_server(NULL, home);
 
        } else if (strcmp(argv[last], "dead") == 0) {
                struct timeval now;
index a641b70af3dc4fc3f5c9a34aae1e14cfef1fed2f..032d25202355cdf13b82a5e2a35da532b5cd512e 100644 (file)
@@ -122,7 +122,7 @@ void request_trace_state_machine(REQUEST *request)
  */
 #define STATE_MACHINE_DECL(_x) static void _x(REQUEST *request, fr_state_action_t action)
 
-static void request_timer(void *ctx, struct timeval *now);
+static void request_timer(struct timeval *now, void *ctx);
 
 /** Insert #REQUEST back into the event heap, to continue executing at a future time
  *
@@ -457,7 +457,7 @@ static int request_init_delay(REQUEST *request)
 /*
  *     Callback for ALL timer events related to the request.
  */
-static void request_timer(void *ctx, UNUSED struct timeval *now)
+static void request_timer(UNUSED struct timeval *now, void *ctx)
 {
        REQUEST *request = talloc_get_type_abort(ctx, REQUEST);
 #ifdef DEBUG_STATE_MACHINE
@@ -1849,7 +1849,7 @@ REQUEST *request_setup(TALLOC_CTX *ctx, rad_listen_t *listener, RADIUS_PACKET *p
 /*
  *     Timer function for all TCP sockets.
  */
-static void tcp_socket_timer(void *ctx, struct timeval *now)
+static void tcp_socket_timer(struct timeval *now, void *ctx)
 {
        rad_listen_t *listener = talloc_get_type_abort(ctx, rad_listen_t);
        listen_socket_t *sock = listener->data;
@@ -3505,7 +3505,7 @@ static void request_ping(REQUEST *request, fr_state_action_t action)
  *     Called from start of zombie period, OR after control socket
  *     marks the home server dead.
  */
-static void ping_home_server(void *ctx, struct timeval *now)
+static void ping_home_server(struct timeval *now, void *ctx)
 {
        home_server_t *home = talloc_get_type_abort(ctx, home_server_t);
        REQUEST *request;
@@ -3762,7 +3762,7 @@ static void mark_home_server_zombie(home_server_t *home, struct timeval *now, st
                        buffer, sizeof(buffer)),
              home->port, (int) response_window->tv_sec, (int) response_window->tv_usec);
 
-       ping_home_server(home, now);
+       ping_home_server(now, home);
 }
 
 
@@ -3789,7 +3789,7 @@ void mark_home_server_dead(home_server_t *home, struct timeval *when)
                        struct timeval now;
 
                        gettimeofday(&now, NULL);
-                       ping_home_server(home, &now);
+                       ping_home_server(&now, home);
                } else {
                        DEBUG("PING: Already pinging home server %s", home->log_name);
                }
@@ -3809,7 +3809,7 @@ void mark_home_server_dead(home_server_t *home, struct timeval *when)
 }
 
 
-void revive_home_server(void *ctx, UNUSED struct timeval *now)
+void revive_home_server(UNUSED struct timeval *now, void *ctx)
 {
        home_server_t *home = talloc_get_type_abort(ctx, home_server_t);
        char buffer[INET6_ADDRSTRLEN];
@@ -4773,7 +4773,7 @@ static void event_socket_handler(NDEBUG_UNUSED fr_event_list_t *xel, UNUSED int
 }
 
 
-static int event_status(UNUSED void *ctx, struct timeval *wake)
+static int event_status(struct timeval *wake, UNUSED void *ctx)
 {
        if (rad_debug_lvl == 0) {
                if (just_started) {
@@ -5041,7 +5041,7 @@ static int event_new_fd(rad_listen_t *this)
  *     Emit a systemd watchdog notification and reschedule the event.
  */
 #ifdef HAVE_SYSTEMD_WATCHDOG
-static void sd_watchdog_event(void *ctx)
+static void sd_watchdog_event(struct timeval *now, void *ctx)
 {
        struct timeval when;
 
@@ -5050,7 +5050,7 @@ static void sd_watchdog_event(void *ctx)
 
        fr_event_list_time(&when, el);
        tv_add(&when, sd_watchdog_interval / 2);
-       if (!fr_event_timer_insert(el, (fr_event_callback_t) sd_watchdog_event, ctx, &when, ctx)) {
+       if (!fr_event_timer_insert(el, sd_watchdog_event, ctx, &when, ctx)) {
                rad_panic("Failed to insert watchdog event");
        }
 }
index 0260aab9ac43f05446b138730d058730764b7dbb..26a1113b08e4ad4977f7eb3ae9723cacc7a32421 100644 (file)
@@ -786,7 +786,7 @@ static void rs_stats_print_csv(rs_update_t *this, rs_stats_t *stats, UNUSED stru
 /** Process stats for a single interval
  *
  */
-static void rs_stats_process(void *ctx, struct timeval *now)
+static void rs_stats_process(struct timeval *now, void *ctx)
 {
        size_t          i;
        size_t          rs_codes_len = (sizeof(rs_useful_codes) / sizeof(*rs_useful_codes));
@@ -1062,7 +1062,7 @@ static void rs_packet_cleanup(rs_request_t *request)
        talloc_free(request);
 }
 
-static void _rs_event(void *ctx, UNUSED struct timeval *now)
+static void _rs_event(UNUSED struct timeval *now, void *ctx)
 {
        rs_request_t *request = talloc_get_type_abort(ctx, rs_request_t);
        request->event = NULL;
@@ -1670,7 +1670,7 @@ 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) {
+                                         &original->when, &original->event) < 0) {
                        REDEBUG("Failed inserting new event");
 
                        talloc_free(original);
@@ -1840,7 +1840,7 @@ static void rs_got_packet(fr_event_list_t *el, int fd, void *ctx)
        }
 }
 
-static int  _rs_event_status(UNUSED void *ctx, struct timeval *wake)
+static int  _rs_event_status(struct timeval *wake, UNUSED void *ctx)
 {
        if (wake && ((wake->tv_sec != 0) || (wake->tv_usec >= 100000))) {
                DEBUG2("Waking up in %d.%01u seconds.", (int) wake->tv_sec, (unsigned int) wake->tv_usec / 100000);
@@ -2000,7 +2000,7 @@ static void _unmark_link(void *request)
 /** Re-open the collectd socket
  *
  */
-static void rs_collectd_reopen(void *ctx, struct timeval *now)
+static void rs_collectd_reopen(struct timeval *now, void *ctx)
 {
        fr_event_list_t *list = ctx;
        static fr_event_timer_t *event;
index 0597a9afc28982b436f8a45349817f9ca8a68f90..0d8cf06b40e126d57400f729278238773f3cc7eb 100644 (file)
@@ -404,7 +404,7 @@ static int timestamp_cmp(void const *one, void const *two)
 /*
  *     Enforce max_request_time.
  */
-static void max_request_time_hook(void *ctx, UNUSED struct timeval *now)
+static void max_request_time_hook(UNUSED struct timeval *now, void *ctx)
 {
        REQUEST *request = talloc_get_type_abort(ctx, REQUEST);
 #ifdef DEBUG_STATE_MACHINE
@@ -551,7 +551,7 @@ static void *thread_handler(void *arg)
 
                                request->el = el;
                                if (fr_event_timer_insert(request->el, max_request_time_hook,
-                                                   request, &when, &request->ev) < 0) {
+                                                         request, &when, &request->ev) < 0) {
                                        REDEBUG("Failed inserting max_request_time");
                                }
                        } while (request != NULL);
index 62adcc158e1ebe178d17a003c9857266ae6d7a7f..f4d87dd198b638cc24b7a244f4d6b611aadbffb6 100644 (file)
@@ -1295,10 +1295,11 @@ static int _unlang_event_free(unlang_event_t *ev)
 
 /** Call the callback registered for a timeout event
  *
- * @param[in] ctx      unlang_event_t structure holding callbacks.
  * @param[in] now      The current time, as held by the event_list.
+ * @param[in] ctx      unlang_event_t structure holding callbacks.
+ *
  */
-static void unlang_event_timeout_handler(void *ctx, struct timeval *now)
+static void unlang_event_timeout_handler(struct timeval *now, void *ctx)
 {
 #ifndef NDEBUG
        unlang_event_t *ev = talloc_get_type_abort(ctx, unlang_event_t);
@@ -1542,7 +1543,7 @@ rlm_rcode_t unlang_yield(REQUEST *request, fr_unlang_resume_t callback,
        return RLM_MODULE_YIELD;
 }
 
-static void unlang_timer_hook(void *ctx, UNUSED struct timeval *now)
+static void unlang_timer_hook(UNUSED struct timeval *now, void *ctx)
 {
        REQUEST *request = talloc_get_type_abort(ctx, REQUEST);
 #ifdef DEBUG_STATE_MACHINE
index ff487dc7527992dec605e35b13f4c5640916bc70..34de93c28a33f20d32a546ae245f4bc3d5a44530 100644 (file)
@@ -230,7 +230,7 @@ typedef struct bfd_socket_t {
 static int bfd_start_packets(bfd_state_t *session);
 static int bfd_start_control(bfd_state_t *session);
 static int bfd_stop_control(bfd_state_t *session);
-static void bfd_detection_timeout(void *ctx, struct timeval *now);
+static void bfd_detection_timeout(struct timeval *now, void *ctx);
 static int bfd_process(bfd_state_t *session, bfd_packet_t *bfd);
 
 static fr_event_list_t *el = NULL; /* don't ask */
@@ -849,7 +849,7 @@ static void bfd_sign(bfd_state_t *session, bfd_packet_t *bfd)
 /*
  *     Send a packet.
  */
-static void bfd_send_packet(void *ctx, UNUSED struct timeval *now)
+static void bfd_send_packet(UNUSED struct timeval *now, void *ctx)
 {
        bfd_state_t *session = ctx;
        bfd_packet_t bfd;
@@ -1079,7 +1079,7 @@ static void bfd_set_desired_min_tx_interval(bfd_state_t *session,
 }
 
 
-static void bfd_detection_timeout(void *ctx, struct timeval *now)
+static void bfd_detection_timeout(struct timeval *now, void *ctx)
 {
        bfd_state_t *session = ctx;
 
index 641cb2effc0c1cc180254fcaad5e7fc1e4c46de4..b5df6e61357162d2047fde9f74aa1fe1bd7713f9 100644 (file)
@@ -457,7 +457,7 @@ static void fr_worker_run_request(fr_worker_t *worker, REQUEST *request)
  * @param[in] ctx the worker
  * @param[in] wake the time when the event loop will wake up.
  */
-static int fr_worker_idle(void *ctx, struct timeval *wake)
+static int fr_worker_idle(struct timeval *wake, void *ctx)
 {
        bool found = false;
        fr_worker_t *worker = ctx;