]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add and use "exit_when_done" flag to the detail listener
authorAlan T. DeKok <aland@freeradius.org>
Wed, 19 Apr 2023 13:12:04 +0000 (09:12 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 19 Apr 2023 13:12:57 +0000 (09:12 -0400)
So that we can use it as a one-shot client for reading and
processing detail files

src/listen/detail/proto_detail.c
src/listen/detail/proto_detail.h
src/listen/detail/proto_detail_file.c
src/listen/detail/proto_detail_work.c

index bb83498b7c7b3037e59ed67e698f0fd1699c6e0c..b8ceadeb265ca7a2fbc2c27e98550de754d38417 100644 (file)
@@ -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
index 49109d31d473e7b5c7e69b4bf12eb9b899e05a94..55b78d9dc59661fe10203b066c4c9accd1d45645 100644 (file)
@@ -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
index 960fcc4e3c363512e8f4a8b94fb6c1768f414782..5eefa8dc90b6d4b6752c83321de0f04a9b543283 100644 (file)
@@ -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;
 }
 
index 624acd4642fab5a6be372e58ed6cba6603396d4e..eecde42c826ed4e6599f385c43b4d538f5631e25 100644 (file)
@@ -25,6 +25,7 @@
 #include <netdb.h>
 #include <freeradius-devel/server/protocol.h>
 #include <freeradius-devel/server/pair.h>
+#include <freeradius-devel/server/main_loop.h>
 #include <freeradius-devel/io/application.h>
 #include <freeradius-devel/io/listen.h>
 #include <freeradius-devel/util/syserror.h>
@@ -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;
 }