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 */
}
-
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;
}
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;
-
}
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;
}
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;
}
/* 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;
}
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) {