From: Alan T. DeKok Date: Wed, 19 Apr 2023 13:12:04 +0000 (-0400) Subject: add and use "exit_when_done" flag to the detail listener X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e53628c6136bc5312f4ccd15210e8a5ade5cafb;p=thirdparty%2Ffreeradius-server.git add and use "exit_when_done" flag to the detail listener So that we can use it as a one-shot client for reading and processing detail files --- diff --git a/src/listen/detail/proto_detail.c b/src/listen/detail/proto_detail.c index bb83498b7c7..b8ceadeb265 100644 --- a/src/listen/detail/proto_detail.c +++ b/src/listen/detail/proto_detail.c @@ -64,6 +64,8 @@ static CONF_PARSER const proto_detail_config[] = { { FR_CONF_OFFSET("max_packet_size", FR_TYPE_UINT32, proto_detail_t, max_packet_size) } , { FR_CONF_OFFSET("num_messages", FR_TYPE_UINT32, proto_detail_t, num_messages) } , + { FR_CONF_OFFSET("exit_when_done", FR_TYPE_BOOL, proto_detail_t, exit_when_done) }, + { FR_CONF_OFFSET("priority", FR_TYPE_UINT32, proto_detail_t, priority) }, CONF_PARSER_TERMINATOR diff --git a/src/listen/detail/proto_detail.h b/src/listen/detail/proto_detail.h index 49109d31d47..55b78d9dc59 100644 --- a/src/listen/detail/proto_detail.h +++ b/src/listen/detail/proto_detail.h @@ -62,6 +62,8 @@ typedef struct { uint32_t num_messages; //!< for message ring buffer uint32_t priority; //!< for packet processing, larger == higher + bool exit_when_done; //!< exit when done reading the current file. + fr_schedule_t *sc; //!< the scheduler, where we insert new readers fr_listen_t *listen; //!< The listener structure which describes diff --git a/src/listen/detail/proto_detail_file.c b/src/listen/detail/proto_detail_file.c index 960fcc4e3c3..5eefa8dc90b 100644 --- a/src/listen/detail/proto_detail_file.c +++ b/src/listen/detail/proto_detail_file.c @@ -510,6 +510,14 @@ retry: if (!inst->poll_interval) return; delay: + /* + * If we're processing one file and exiting, then the input file must exist. + */ + if (inst->immediate && inst->parent->exit_when_done) { + ERROR("Input file does not exist"); + fr_exit(EXIT_FAILURE); + } + /* * Check every N seconds. */ @@ -652,6 +660,11 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) */ inst->mode = O_RDWR; + if (inst->parent->exit_when_done && !inst->immediate) { + cf_log_warn(conf, "Ignoring 'exit_when_done' due to 'immediate' flag not being set"); + inst->parent->exit_when_done = false; + } + return 0; } diff --git a/src/listen/detail/proto_detail_work.c b/src/listen/detail/proto_detail_work.c index 624acd4642f..eecde42c826 100644 --- a/src/listen/detail/proto_detail_work.c +++ b/src/listen/detail/proto_detail_work.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -721,6 +722,8 @@ static int mod_open(fr_listen_t *li) static int mod_close_internal(proto_detail_work_thread_t *thread) { + proto_detail_work_t const *inst = talloc_get_type_abort_const(thread->inst, proto_detail_work_t); + /* * One less worker... we check for "0" because of the * hacks in proto_detail which let us start up with @@ -752,6 +755,11 @@ static int mod_close_internal(proto_detail_work_thread_t *thread) talloc_free(thread->listen); } + if (inst->parent->exit_when_done) { + fr_event_list_t *el = main_loop_event_list(); + fr_event_loop_exit(el, 1); + } + return 0; }