From: Arran Cudbard-Bell Date: Sat, 26 Nov 2016 01:15:09 +0000 (-0500) Subject: reorder arguments to timer callbacks X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c3ebeba2f3f0a67694fe3d272078f2ea8770378;p=thirdparty%2Ffreeradius-server.git reorder arguments to timer callbacks --- diff --git a/src/include/event.h b/src/include/event.h index b7b14ae1f13..70c893c8ab8 100644 --- a/src/include/event.h +++ b/src/include/event.h @@ -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); diff --git a/src/include/radiusd.h b/src/include/radiusd.h index 16ccf295081..64107d200a9 100644 --- a/src/include/radiusd.h +++ b/src/include/radiusd.h @@ -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 */ diff --git a/src/main/command.c b/src/main/command.c index cc123108885..499f35ce4f8 100644 --- a/src/main/command.c +++ b/src/main/command.c @@ -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; diff --git a/src/main/process.c b/src/main/process.c index a641b70af3d..032d2520235 100644 --- a/src/main/process.c +++ b/src/main/process.c @@ -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"); } } diff --git a/src/main/radsniff.c b/src/main/radsniff.c index 0260aab9ac4..26a1113b08e 100644 --- a/src/main/radsniff.c +++ b/src/main/radsniff.c @@ -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; diff --git a/src/main/threads.c b/src/main/threads.c index 0597a9afc28..0d8cf06b40e 100644 --- a/src/main/threads.c +++ b/src/main/threads.c @@ -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); diff --git a/src/main/unlang.c b/src/main/unlang.c index 62adcc158e1..f4d87dd198b 100644 --- a/src/main/unlang.c +++ b/src/main/unlang.c @@ -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 diff --git a/src/modules/proto_bfd/proto_bfd.c b/src/modules/proto_bfd/proto_bfd.c index ff487dc7527..34de93c28a3 100644 --- a/src/modules/proto_bfd/proto_bfd.c +++ b/src/modules/proto_bfd/proto_bfd.c @@ -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; diff --git a/src/util/worker.c b/src/util/worker.c index 641cb2effc0..b5df6e61357 100644 --- a/src/util/worker.c +++ b/src/util/worker.c @@ -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;