From: Arran Cudbard-Bell Date: Sun, 23 Apr 2017 00:40:47 +0000 (-0400) Subject: Add event list to event callback args X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=09d5dcfff05539d714193ca53b9f65c1d87c57bd;p=thirdparty%2Ffreeradius-server.git Add event list to event callback args --- diff --git a/src/include/event.h b/src/include/event.h index fc1b1700c59..66905ebc6ee 100644 --- a/src/include/event.h +++ b/src/include/event.h @@ -51,7 +51,7 @@ typedef struct fr_event_timer_t fr_event_timer_t; * @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); +typedef void (*fr_event_callback_t)(fr_event_list_t *el, struct timeval *now, void *ctx); /** Called after each event loop cycle * diff --git a/src/include/radiusd.h b/src/include/radiusd.h index 9aaa8ce9929..78c7dcdf9ff 100644 --- a/src/include/radiusd.h +++ b/src/include/radiusd.h @@ -615,13 +615,13 @@ typedef enum event_corral_t { EVENT_CORRAL_AUX //!< Maybe main thread or one shared by modules } event_corral_t; -fr_event_list_t *radius_event_list_corral(event_corral_t hint); +fr_event_list_t *process_global_event_list(event_corral_t hint); int radius_event_init(TALLOC_CTX *ctx); 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(struct timeval *now, void *ctx); +void revive_home_server(fr_event_list_t *el, struct timeval *now, void *ctx); void mark_home_server_dead(home_server_t *home, struct timeval *when); /* evaluate.c */ diff --git a/src/lib/util/event.c b/src/lib/util/event.c index 2056dadd059..d579fe73b5a 100644 --- a/src/lib/util/event.c +++ b/src/lib/util/event.c @@ -611,7 +611,7 @@ int fr_event_timer_run(fr_event_list_t *el, struct timeval *when) */ fr_event_timer_delete(el, ev->parent); - callback(when, ctx); + callback(el, when, ctx); return 1; } diff --git a/src/lib/util/print.c b/src/lib/util/print.c index 526e2c2c0a9..62b4410ab97 100644 --- a/src/lib/util/print.c +++ b/src/lib/util/print.c @@ -687,6 +687,18 @@ char *fr_vasprintf(TALLOC_CTX *ctx, char const *fmt, va_list ap) goto do_splice; } + case 'T': + { + struct timeval *in = va_arg(ap_q, struct timeval *); + + subst = talloc_asprintf(NULL, "%" PRIu64 ".%06" PRIu64, + (uint64_t)in->tv_sec, + (uint64_t)in->tv_usec); + if (!subst) goto oom; + + goto do_splice; + } + default: (void) va_arg(ap_q, void *); /* void * */ } diff --git a/src/main/command.c b/src/main/command.c index 7dd2006b36d..db14cdda7b7 100644 --- a/src/main/command.c +++ b/src/main/command.c @@ -1892,7 +1892,7 @@ static int command_set_home_server_state(rad_listen_t *listener, int argc, char } if (strcmp(argv[last], "alive") == 0) { - revive_home_server(NULL, home); + revive_home_server(NULL, 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 9092cb4f70c..c35ead01c44 100644 --- a/src/main/process.c +++ b/src/main/process.c @@ -66,7 +66,7 @@ static fr_event_list_t *el = NULL; static void mark_home_server_alive(REQUEST *request, home_server_t *home); -fr_event_list_t *radius_event_list_corral(UNUSED event_corral_t hint) { +fr_event_list_t *process_global_event_list(UNUSED event_corral_t hint) { /* Currently we do not run a second event loop for modules. */ return el; } @@ -123,7 +123,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(struct timeval *now, void *ctx); +static void request_timer(fr_event_list_t *eel, struct timeval *now, void *ctx); /** Insert #REQUEST back into the event heap, to continue executing at a future time * @@ -458,7 +458,7 @@ static int request_init_delay(REQUEST *request) /* * Callback for ALL timer events related to the request. */ -static void request_timer(UNUSED struct timeval *now, void *ctx) +static void request_timer(UNUSED fr_event_list_t *eel, UNUSED struct timeval *now, void *ctx) { REQUEST *request = talloc_get_type_abort(ctx, REQUEST); #ifdef DEBUG_STATE_MACHINE @@ -1850,7 +1850,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(struct timeval *now, void *ctx) +static void tcp_socket_timer(UNUSED fr_event_list_t *eel, struct timeval *now, void *ctx) { rad_listen_t *listener = talloc_get_type_abort(ctx, rad_listen_t); listen_socket_t *sock = listener->data; @@ -3506,7 +3506,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(struct timeval *now, void *ctx) +static void ping_home_server(UNUSED fr_event_list_t *eel, struct timeval *now, void *ctx) { home_server_t *home = talloc_get_type_abort(ctx, home_server_t); REQUEST *request; @@ -3774,7 +3774,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(now, home); + ping_home_server(el, now, home); } @@ -3801,7 +3801,7 @@ void mark_home_server_dead(home_server_t *home, struct timeval *when) struct timeval now; gettimeofday(&now, NULL); - ping_home_server(&now, home); + ping_home_server(el, &now, home); } else { DEBUG("PING: Already pinging home server %s", home->log_name); } @@ -3821,7 +3821,7 @@ void mark_home_server_dead(home_server_t *home, struct timeval *when) } -void revive_home_server(UNUSED struct timeval *now, void *ctx) +void revive_home_server(UNUSED fr_event_list_t *eel, UNUSED struct timeval *now, void *ctx) { home_server_t *home = talloc_get_type_abort(ctx, home_server_t); char buffer[INET6_ADDRSTRLEN]; diff --git a/src/main/radsniff.c b/src/main/radsniff.c index 751e80a184a..778689e31ef 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(struct timeval *now, void *ctx) +static void rs_stats_process(fr_event_list_t *el, struct timeval *now, void *ctx) { size_t i; size_t rs_codes_len = (sizeof(rs_useful_codes) / sizeof(*rs_useful_codes)); @@ -850,7 +850,7 @@ clear: now->tv_sec += conf->stats.interval; now->tv_usec = 0; - if (fr_event_timer_insert(this->list, rs_stats_process, ctx, now, &event) < 0) { + if (fr_event_timer_insert(el, rs_stats_process, ctx, now, &event) < 0) { ERROR("Failed inserting stats interval event"); } } @@ -1062,7 +1062,7 @@ static void rs_packet_cleanup(rs_request_t *request) talloc_free(request); } -static void _rs_event(UNUSED struct timeval *now, void *ctx) +static void _rs_event(UNUSED fr_event_list_t *el, UNUSED struct timeval *now, void *ctx) { rs_request_t *request = talloc_get_type_abort(ctx, rs_request_t); request->event = NULL; @@ -2000,9 +2000,8 @@ static void _unmark_link(void *request) /** Re-open the collectd socket * */ -static void rs_collectd_reopen(struct timeval *now, void *ctx) +static void rs_collectd_reopen(fr_event_list_t *el, struct timeval *now, UNUSED void *ctx) { - fr_event_list_t *list = ctx; static fr_event_timer_t *event; struct timeval when; @@ -2014,7 +2013,7 @@ static void rs_collectd_reopen(struct timeval *now, void *ctx) 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(list, rs_collectd_reopen, list, &when, &event) < 0) { + if (fr_event_timer_insert(el, rs_collectd_reopen, el, &when, &event) < 0) { ERROR("Failed inserting re-open event"); RS_ASSERT(0); } @@ -2064,7 +2063,7 @@ fr_event_list_t *list, int fd, UNUSED void *ctx) struct timeval now; gettimeofday(&now, NULL); - rs_collectd_reopen(&now, list); + rs_collectd_reopen(list, &now, list); } break; #else diff --git a/src/main/threads.c b/src/main/threads.c index 21ef1cb16d6..eb9ba2cd42e 100644 --- a/src/main/threads.c +++ b/src/main/threads.c @@ -394,7 +394,7 @@ static int timestamp_cmp(void const *one, void const *two) /* * Enforce max_request_time. */ -static void max_request_time_hook(UNUSED struct timeval *now, void *ctx) +static void max_request_time_hook(UNUSED fr_event_list_t *el, UNUSED struct timeval *now, void *ctx) { REQUEST *request = talloc_get_type_abort(ctx, REQUEST); #ifdef DEBUG_STATE_MACHINE diff --git a/src/main/unlang_interpret.c b/src/main/unlang_interpret.c index f2f466b585e..6a9cbced67d 100644 --- a/src/main/unlang_interpret.c +++ b/src/main/unlang_interpret.c @@ -124,10 +124,10 @@ static uint64_t collect_active_callers(unlang_t *instruction) thread = module_thread_instance_find(sp->module_instance); rad_assert(thread != NULL); - + return thread->active_callers; } - + case UNLANG_TYPE_GROUP: case UNLANG_TYPE_LOAD_BALANCE: case UNLANG_TYPE_REDUNDANT_LOAD_BALANCE: @@ -271,7 +271,7 @@ static unlang_action_t unlang_load_balance(REQUEST *request, unlang_stack_t *sta thread = module_thread_instance_find(sp->module_instance); rad_assert(thread != NULL); - + active_callers = thread->active_callers; RDEBUG3("load-balance child %d sub-module has %" PRIu64 " active", num, active_callers); } @@ -1437,11 +1437,12 @@ static int _unlang_event_free(unlang_event_t *ev) /** Call the callback registered for a timeout event * + * @param[in] el the event timer was inserted into. * @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(struct timeval *now, void *ctx) +static void unlang_event_timeout_handler(UNUSED fr_event_list_t *el, struct timeval *now, void *ctx) { unlang_event_t *ev = talloc_get_type_abort(ctx, unlang_event_t); void *mutable_ctx; @@ -1700,7 +1701,7 @@ rlm_rcode_t unlang_yield(REQUEST *request, fr_unlang_resume_t callback, return RLM_MODULE_YIELD; } -static void unlang_timer_hook(UNUSED struct timeval *now, void *ctx) +static void unlang_timer_hook(UNUSED fr_event_list_t *el, 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 2d944808fd9..50324de443f 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(struct timeval *now, void *ctx); +static void bfd_detection_timeout(UNUSED fr_event_list_t *eel, 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 */ @@ -854,7 +854,7 @@ static void bfd_sign(bfd_state_t *session, bfd_packet_t *bfd) /* * Send a packet. */ -static void bfd_send_packet(UNUSED struct timeval *now, void *ctx) +static void bfd_send_packet(UNUSED fr_event_list_t *eel, UNUSED struct timeval *now, void *ctx) { bfd_state_t *session = ctx; bfd_packet_t bfd; @@ -1084,7 +1084,7 @@ static void bfd_set_desired_min_tx_interval(bfd_state_t *session, } -static void bfd_detection_timeout(struct timeval *now, void *ctx) +static void bfd_detection_timeout(UNUSED fr_event_list_t *eel, struct timeval *now, void *ctx) { bfd_state_t *session = ctx; diff --git a/src/modules/rlm_rest/io.c b/src/modules/rlm_rest/io.c index ec24827aaa9..ce98a7dd4b9 100644 --- a/src/modules/rlm_rest/io.c +++ b/src/modules/rlm_rest/io.c @@ -119,10 +119,11 @@ static inline void _rest_io_service(rlm_rest_thread_t *t, int fd, int event) /** libcurl's timer expired * + * @param[in] el the timer was inserted into. * @param[in] now The current time according to the event loop. * @param[in] ctx The rlm_rest_thread_t specific to this thread. */ -static void _rest_io_timer_expired(UNUSED struct timeval *now, void *ctx) +static void _rest_io_timer_expired(UNUSED fr_event_list_t *el, UNUSED struct timeval *now, void *ctx) { rlm_rest_thread_t *t; diff --git a/src/modules/rlm_unbound/rlm_unbound.c b/src/modules/rlm_unbound/rlm_unbound.c index c121593fad2..ff86c1eb538 100644 --- a/src/modules/rlm_unbound/rlm_unbound.c +++ b/src/modules/rlm_unbound/rlm_unbound.c @@ -406,7 +406,7 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance) char k[64]; /* To silence const warns until newer unbound in distros */ - inst->el = radius_event_list_corral(EVENT_CORRAL_AUX); + inst->el = process_global_event_list(EVENT_CORRAL_AUX); inst->log_pipe_stream[0] = NULL; inst->log_pipe_stream[1] = NULL; inst->log_fd = -1;