From: Thibault Godouet Date: Tue, 31 Dec 2024 23:08:21 +0000 (+0000) Subject: Defer any work outside of the signal handlers. X-Git-Tag: ver3_3_3~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=867981e08a437a16df91cc0236ac25e9a7eb5256;p=thirdparty%2Ffcron.git Defer any work outside of the signal handlers. This is to make sure we don't inadvertently call a non-async-signal safe function (see the signal-safety(7) man page). --- diff --git a/fcron.c b/fcron.c index 7abc6ca..7847f26 100644 --- a/fcron.c +++ b/fcron.c @@ -94,6 +94,7 @@ char sig_conf = 0; /* is 1 when we got a SIGHUP, 2 for a SIGUSR1 */ char sig_chld = 0; /* is 1 when we got a SIGCHLD */ char sig_debug = 0; /* is 1 when we got a SIGUSR2 */ char sig_cont = 0; /* is 1 when we got a SIGCONT */ +bool sig_term = false; /* true if we got a SIGTERM */ /* jobs database */ struct cf_t *file_base; /* point to the first file of the list */ @@ -478,24 +479,24 @@ create_spooldir(char *dir) } - void sigterm_handler(int x) /* exit safely */ { - debug(""); - explain("SIGTERM signal received"); - xexit(EXIT_OK); + /* Defer any work outside of the handler, by fear of inadvertently calling + * a non-async-signal safe function (see the signal-safety(7) man page). */ + sig_term = true; } void sighup_handler(int x) /* update configuration */ { - /* we don't call the synchronize_dir() function directly, - * because it may cause some problems if this signal - * is not received during the sleep - */ + /* Defer any work outside of the handler, by fear of inadvertently calling + * a non-async-signal safe function (see the signal-safety(7) man page). + * In particular, we don't call the synchronize_dir() function directly, + * because it may cause some problems if this signal is not received during + * the sleep */ sig_conf = 1; } @@ -503,9 +504,9 @@ void sigchild_handler(int x) /* call wait_chld() to take care of finished jobs */ { - + /* Defer any work outside of the handler, by fear of inadvertently calling + * a non-async-signal safe function (see the signal-safety(7) man page). */ sig_chld = 1; - } @@ -513,10 +514,11 @@ void sigusr1_handler(int x) /* reload all configurations */ { - /* we don't call the synchronize_dir() function directly, - * because it may cause some problems if this signal - * is not received during the sleep - */ + /* Defer any work outside of the handler, by fear of inadvertently calling + * a non-async-signal safe function (see the signal-safety(7) man page). + * In particular, we don't call the synchronize_dir() function directly, + * because it may cause some problems if this signal is not received during + * the sleep */ sig_conf = 2; } @@ -525,6 +527,8 @@ void sigusr2_handler(int x) /* print schedule and switch on/off debug mode */ { + /* Defer any work outside of the handler, by fear of inadvertently calling + * a non-async-signal safe function (see the signal-safety(7) man page). */ sig_debug = 1; } @@ -533,6 +537,8 @@ sigcont_handler(int x) /* used to notify fcron of a system resume after suspend. * However this signal could also be received in other cases. */ { + /* Defer any work outside of the handler, by fear of inadvertently calling + * a non-async-signal safe function (see the signal-safety(7) man page). */ sig_cont = 1; } @@ -776,6 +782,12 @@ check_signal() wait_chld(); sig_chld = 0; reinstall_signal_handler(SIGCHLD, sigchild_handler); + + if (sig_term == true) { + sig_term = false; + debug(""); + explain("SIGTERM signal received"); + xexit(EXIT_OK); } if (sig_conf > 0) {