aboutsummaryrefslogtreecommitdiff
path: root/slave.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-11-03 12:24:15 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-11-03 12:24:15 +0000
commit61dfa1365ea65b3b133153c583a7a7d3764eaadd (patch)
tree3dc089ddd224a797867ac3ea9a43da6f2905c360 /slave.c
parentmain: ignore SIGHUP in master process (diff)
slave: restore signals before calling exec()
Diffstat (limited to 'slave.c')
-rw-r--r--slave.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/slave.c b/slave.c
index 939293dd..0b453c5d 100644
--- a/slave.c
+++ b/slave.c
@@ -5,6 +5,7 @@
#include <unistd.h>
#include <errno.h>
#include <assert.h>
+#include <signal.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -88,6 +89,18 @@ slave_spawn(int ptmx, int argc, char *const *argv,
/* Child */
close(fork_pipe[0]); /* Close read end */
+ /* Restore signals */
+ const struct sigaction sa = {.sa_handler = SIG_DFL};
+ if (sigaction(SIGINT, &sa, NULL) < 0 ||
+ sigaction(SIGTERM, &sa, NULL) < 0 ||
+ sigaction(SIGHUP, &sa, NULL) < 0)
+ {
+ const int _errno = errno;
+ LOG_ERRNO_P("failed to restore signals", errno);
+ (void)!write(fork_pipe[1], &_errno, sizeof(_errno));
+ _exit(_errno);
+ }
+
setenv("TERM", term_env, 1);
char **_shell_argv = NULL;
@@ -134,7 +147,6 @@ slave_spawn(int ptmx, int argc, char *const *argv,
LOG_ERRNO("failed to set FD_CLOEXEC on ptmx");
return -1;
}
-
break;
}
}