]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add event list to event callback args
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 23 Apr 2017 00:40:47 +0000 (20:40 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 25 Apr 2017 21:42:13 +0000 (17:42 -0400)
12 files changed:
src/include/event.h
src/include/radiusd.h
src/lib/util/event.c
src/lib/util/print.c
src/main/command.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/rlm_rest/io.c
src/modules/rlm_unbound/rlm_unbound.c

index fc1b1700c59e5a9aff3b0db2adc907037f2febe7..66905ebc6ee62f239e6dfff5fa08798c98ecea34 100644 (file)
@@ -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
  *
index 9aaa8ce99290ff94f8fb5777f1cf1defddad744a..78c7dcdf9ff0b3c09ee311e4b2728f6fddb1d396 100644 (file)
@@ -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 */
index 2056dadd0596436afd53dbe1e785035f5393979c..d579fe73b5a390aa8dfef70315fbd906cb0bfacc 100644 (file)
@@ -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;
 }
index 526e2c2c0a985091149da6f960042be193fa4336..62b4410ab9739ed6aab8916f5c50d25b5da74b04 100644 (file)
@@ -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 * */
                        }
index 7dd2006b36d56ef1b2f609cea629d5282acf1f68..db14cdda7b75a9437143ac5b4e10ed7d63b95be3 100644 (file)
@@ -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;
index 9092cb4f70c005a40dfaa0b72b10c42bd8b44ce3..c35ead01c4453e6fb7c56971ba52f42b8686ddc8 100644 (file)
@@ -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];
index 751e80a184ae2b3a5226e1faf2d2244601424ce4..778689e31ef9d774de4b625773f3fa85d07d1525 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(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
index 21ef1cb16d6992d6538b4d2a3faa01da3cf75e4e..eb9ba2cd42e22934858ab6be51bc5bb9d4f9ae57 100644 (file)
@@ -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
index f2f466b585e10342b8692051f71b3484cb9a7d95..6a9cbced67d6f9a3a386753f2c00c339f8d8174a 100644 (file)
@@ -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
index 2d944808fd97af54134acb8b6817ff7d09d8c5fa..50324de443fd68947b68b72aa7ad04ba51b0e57c 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(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;
 
index ec24827aaa93d036c58912791dcef030fda54582..ce98a7dd4b94dfa301abd546298bcb4452bb86c7 100644 (file)
@@ -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;
 
index c121593fad2e903ed596cc750fe9c2093d3bdee3..ff86c1eb5381ba94915f51335589a456c8ecdeca 100644 (file)
@@ -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;