- for (sig = SIGHUP; sig <= SIGUNUSED; sig++) {
- /* Skip unblockable signals. */
- if (sig == SIGKILL || sig == SIGSTOP) {
- continue;
- }
- if (signal(sig, SIG_DFL) == SIG_ERR) {
- PERROR("reset signal %d", sig);
- }
+ for (sig = 1; sig <= 31; sig++) {
+ (void) signal(sig, SIG_DFL);
+ }
+ return 0;
+}
+
+static
+void worker_sighandler(int sig)
+{
+ const char *signame;
+
+ /*
+ * The worker will inherit its parent's signals since they are part of
+ * the same process group. However, in the case of SIGINT and SIGTERM,
+ * we want to give the worker a chance to teardown gracefully when its
+ * parent closes the command socket.
+ */
+ switch (sig) {
+ case SIGINT:
+ signame = "SIGINT";
+ break;
+ case SIGTERM:
+ signame = "SIGTERM";
+ break;
+ default:
+ signame = NULL;
+ }
+
+ if (signame) {
+ DBG("run_as worker received signal %s", signame);
+ } else {
+ DBG("run_as_worker received signal %d", sig);
+ }
+}
+
+static
+int set_worker_sighandlers(void)
+{
+ int ret = 0;
+ sigset_t sigset;
+ struct sigaction sa;
+
+ if ((ret = sigemptyset(&sigset)) < 0) {
+ PERROR("sigemptyset");
+ goto end;