]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Try altering where the semaphore is cleaned up
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 28 Apr 2021 13:15:01 +0000 (08:15 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 28 Apr 2021 14:20:41 +0000 (09:20 -0500)
src/bin/radiusd.c
src/lib/server/main_config.c
src/lib/server/main_config.h

index babe992244fff5e0b74719f364623f06b060334e..5a502b95e5f230ac99c9cf3188d364bcb913d8b2 100644 (file)
@@ -997,6 +997,16 @@ int main(int argc, char *argv[])
                INFO("All threads have exited, sending SIGTERM to remaining children");
                kill(-radius_pid, SIGTERM);
        }
+
+       /*
+        *      Remove the semaphore, allowing other processes
+        *      to start.  We do this before the cleanup label
+        *      as the parent process MUST NOT call this
+        *      function as it exits, otherwise the semaphore
+        *      is removed and there's no exclusivity.
+        */
+       main_config_exclusive_proc_done(main_config);
+
 cleanup:
        /*
         *      This may not have been done earlier if we're
index 8851c80e6db42f32569f89f6e55085482dfe1108..f6a12ac76e5f911fe6aaf310151c37ac2c083ed6 100644 (file)
@@ -826,10 +826,9 @@ void main_config_raddb_dir_set(main_config_t *config, char const *name)
  * running the process under something like systemd and running it under
  * debug mode.
  */
-static int _exclusive_proc_close_sem(unsigned int *sem_id_p)
+void main_config_exclusive_proc_done(main_config_t *config)
 {
-       fr_sem_close(*sem_id_p, NULL);
-       return 0;
+       fr_sem_close(config->multi_proc_sem_id, NULL);
 }
 
 /** Check to see if we're the only process using this configuration file
@@ -862,15 +861,8 @@ int main_config_exclusive_proc(main_config_t *config)
        ret = fr_sem_wait(sem_id, path, true, true);
        switch (ret) {
        case 0: /* we have the semaphore */
-       {
-               unsigned int *sem_id_p;
-
-               MEM(sem_id_p = talloc(config, unsigned int));
-               *sem_id_p = sem_id;
-               talloc_set_destructor(sem_id_p, _exclusive_proc_close_sem);
-
+               config->multi_proc_sem_id = sem_id;
                sem_initd = true;
-       }
                break;
 
        case 1: /* another process has the semaphore */
index a267fa5641088ee99ceb20e02e93bdd0f2dbcd8f..f3ef714f7d07ec8ff09378e942fb6c799034e1eb 100644 (file)
@@ -135,6 +135,7 @@ struct main_config_s {
                                                        //!< threaded mode.
        bool            allow_multiple_procs;           //!< Allow multiple instances of radiusd to run with the
                                                        ///< same config file.
+       unsigned int    multi_proc_sem_id;              //!< Semaphore we use to prevent multiple processes running.
 
        uint32_t        max_networks;                   //!< for the scheduler
        uint32_t        max_workers;                    //!< for the scheduler
@@ -145,6 +146,8 @@ struct main_config_s {
 void                   main_config_name_set_default(main_config_t *config, char const *name, bool overwrite_config);
 void                   main_config_raddb_dir_set(main_config_t *config, char const *path);
 void                   main_config_dict_dir_set(main_config_t *config, char const *path);
+
+void                   main_config_exclusive_proc_done(main_config_t  const *config);
 int                    main_config_exclusive_proc(main_config_t *config);
 
 main_config_t          *main_config_alloc(TALLOC_CTX *ctx);