]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fix random ungraceful exits
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 13 May 2024 04:07:57 +0000 (22:07 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 13 May 2024 13:42:30 +0000 (07:42 -0600)
src/bin/radiusd.c

index 62d71ed8161d2450df692987a75a9c3eabb19302..a178d385d780a1f6358e6fe276dcfe54201ea865 100644 (file)
@@ -1058,6 +1058,15 @@ int main(int argc, char *argv[])
         */
        if (config->spawn_workers) {
                INFO("All threads have exited, sending SIGTERM to remaining children");
+
+               /*
+                *      If pid is negative, but not -1, sig
+                *      shall be sent to all processes
+                *      (excluding an unspecified set of system processes)
+                *      whose process group ID is equal to the absolute value
+                *      of pid, and for which the process has permission t
+                *      to send a signal.
+                */
                kill(-radius_pid, SIGTERM);
        }
 
@@ -1197,8 +1206,23 @@ static NEVER_RETURNS void usage(main_config_t const *config, int status)
  */
 static void sig_fatal(int sig)
 {
+       static int last_sig;
+
        if (getpid() != radius_pid) _exit(sig);
 
+       /*
+        *      Suppress duplicate signals.
+        *
+        *      For some reason on macOS we get multiple signals
+        *      for the same event (SIGTERM).
+        *
+        *      ...this also fixes the problem of the user hammering
+        *      Ctrl-C and causing ungraceful exits as we try and
+        *      write out signals to a pipe that's already closed.
+        */
+       if (sig == last_sig) return;
+       last_sig = sig;
+
        switch (sig) {
        case SIGTERM:
                main_loop_signal_raise(RADIUS_SIGNAL_SELF_TERM);