Navigation Menu

Skip to content

Commit

Permalink
Unblock all signals blocked by finit when starting children
Browse files Browse the repository at this point in the history
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
  • Loading branch information
troglobit committed Jan 18, 2015
1 parent 425cd17 commit e0529a5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
14 changes: 5 additions & 9 deletions helpers.c
Expand Up @@ -466,7 +466,9 @@ int run(char *cmd)
dup2(fd, STDERR_FILENO);
}

sig_unblock();
execvp(args[0], args);

_exit(1); /* Only if execv() fails. */
} else if (-1 == pid) {
_pe("%s", args[0]);
Expand Down Expand Up @@ -566,10 +568,8 @@ pid_t run_getty(char *cmd, char *args[], int console)
pid_t pid = vfork();

if (!pid) {
int i, fd;
int fd;
char c;
sigset_t nmask;
struct sigaction sa;

if (console) {
/* Detach from initial controlling TTY */
Expand All @@ -590,13 +590,8 @@ pid_t run_getty(char *cmd, char *args[], int console)

prctl(PR_SET_NAME, "console", 0, 0, 0);
}
sigemptyset(&nmask);
sigaddset(&nmask, SIGCHLD);
sigprocmask(SIG_UNBLOCK, &nmask, NULL);

/* Reset signal handlers that were set by the parent process */
for (i = 1; i < NSIG; i++)
DFLSIG(sa, i, 0);
sig_unblock();

while (!fexist(SYNC_SHUTDOWN)) {
static const char msg[] = "\nPlease press Enter to activate this console.";
Expand Down Expand Up @@ -672,6 +667,7 @@ int run_parts(char *dir, char *cmd)
pid = vfork();
if (!pid) {
_d("Calling %s ...", path);
sig_unblock();
execv(path, args);
exit(0);
}
Expand Down
23 changes: 23 additions & 0 deletions sig.c
Expand Up @@ -148,6 +148,29 @@ void sig_init(void)
SETSIG(sa, SIGCHLD, chld_handler, SA_RESTART);
}

/*
* Unblock all signals blocked by finit when starting children
*/
void sig_unblock(void)
{
int i;
sigset_t nmask;
struct sigaction sa;

sigemptyset(&nmask);
sigaddset(&nmask, SIGCHLD);
sigaddset(&nmask, SIGINT);
sigaddset(&nmask, SIGPWR);
sigaddset(&nmask, SIGSTOP);
sigaddset(&nmask, SIGTSTP);
sigaddset(&nmask, SIGCONT);
sigprocmask(SIG_UNBLOCK, &nmask, NULL);

/* Reset signal handlers that were set by the parent process */
for (i = 1; i < NSIG; i++)
DFLSIG(sa, i, 0);
}

/*
* Setup limited set of SysV compatible signals to respond to
*/
Expand Down
1 change: 1 addition & 0 deletions sig.h
Expand Up @@ -58,6 +58,7 @@
void do_shutdown (int sig);
int sig_stopped (void);
void sig_init (void);
void sig_unblock (void);
void sig_setup (uev_ctx_t *ctx);

#endif /* FINIT_SIG_H_ */
Expand Down

0 comments on commit e0529a5

Please sign in to comment.