From: Arran Cudbard-Bell Date: Mon, 13 May 2024 04:07:57 +0000 (-0600) Subject: Fix random ungraceful exits X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=67efbb4a29372eae4cfc639b9807e7052337696e;p=thirdparty%2Ffreeradius-server.git Fix random ungraceful exits --- diff --git a/src/bin/radiusd.c b/src/bin/radiusd.c index 62d71ed8161..a178d385d78 100644 --- a/src/bin/radiusd.c +++ b/src/bin/radiusd.c @@ -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);