int send_afs_status(struct command_context *cc, int parser_friendly);
static bool subcmd_should_die;
+/*
+ * Don't call PARA_XXX_LOG() here as we might already hold the log mutex. See
+ * generic_signal_handler() for details.
+ */
static void command_handler_sighandler(int s)
{
- if (s != SIGTERM)
- return;
- PARA_EMERG_LOG("terminating on signal %d\n", SIGTERM);
- subcmd_should_die = true;
+ if (s == SIGTERM)
+ subcmd_should_die = true;
}
/*
* open a race window similar to the one described above.
*/
pselect(1, NULL, NULL, NULL, &ts, &set);
- if (subcmd_should_die)
+ if (subcmd_should_die) {
+ PARA_EMERG_LOG("terminating on SIGTERM\n");
goto out;
+ }
ret = -E_SERVER_CRASH;
if (getppid() == 1)
goto out;
errno = save_errno;
return;
}
- if (ret < 0)
- PARA_EMERG_LOG("%s\n", strerror(errno));
- else
- PARA_EMERG_LOG("short write to signal pipe\n");
+ /*
+ * This is a fatal error which should never happen. We must not call
+ * PARA_XXX_LOG() here because this might acquire the log mutex which
+ * is already taken by the main program if the interrupt occurs while a
+ * log message is being printed. The mutex will not be released as long
+ * as this signal handler is running, so a deadlock ensues.
+ */
exit(EXIT_FAILURE);
}