Skip to content

Commit

Permalink
Merge pull request #104 from chriskuehl/set-signal-mask-before-fork
Browse files Browse the repository at this point in the history
Set the signal mask before forking
  • Loading branch information
asottile authored Jul 26, 2016
2 parents 90bfe0f + d17ab8a commit 74bdd54
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions dumb-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,17 @@ char **parse_command(int argc, char *argv[]) {

int main(int argc, char *argv[]) {
char **cmd = parse_command(argc, argv);
sigset_t all_signals;
sigfillset(&all_signals);
sigprocmask(SIG_BLOCK, &all_signals, NULL);

child_pid = fork();
if (child_pid < 0) {
PRINTERR("Unable to fork. Exiting.\n");
return 1;
} else if (child_pid == 0) {
/* child */
sigprocmask(SIG_UNBLOCK, &all_signals, NULL);
if (use_setsid) {
if (setsid() == -1) {
PRINTERR(
Expand All @@ -260,13 +264,9 @@ int main(int argc, char *argv[]) {
return 2;
} else {
/* parent */
int signum;
sigset_t all_signals;
sigfillset(&all_signals);
sigprocmask(SIG_BLOCK, &all_signals, NULL);

DEBUG("Child spawned with PID %d.\n", child_pid);
for (;;) {
int signum;
sigwait(&all_signals, &signum);
handle_signal(signum);
}
Expand Down

0 comments on commit 74bdd54

Please sign in to comment.