Commit 0291b5fa by Qiang Huang Committed by Stéphane Graber

lxc_init.c: error handing for sigaction and sigprocmask

Look through all LXC code and seems like only here are missed. Signed-off-by: 's avatarQiang Huang <h.huangqiang@huawei.com> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent 3dcb8ff3
...@@ -123,11 +123,14 @@ int main(int argc, char *argv[]) ...@@ -123,11 +123,14 @@ int main(int argc, char *argv[])
* mask all the signals so we are safe to install a * mask all the signals so we are safe to install a
* signal handler and to fork * signal handler and to fork
*/ */
sigfillset(&mask); if (sigfillset(&mask) ||
sigdelset(&mask, SIGILL); sigdelset(&mask, SIGILL) ||
sigdelset(&mask, SIGSEGV); sigdelset(&mask, SIGSEGV) ||
sigdelset(&mask, SIGBUS); sigdelset(&mask, SIGBUS) ||
sigprocmask(SIG_SETMASK, &mask, &omask); sigprocmask(SIG_SETMASK, &mask, &omask)) {
SYSERROR("failed to set signal mask");
exit(EXIT_FAILURE);
}
for (i = 1; i < NSIG; i++) { for (i = 1; i < NSIG; i++) {
struct sigaction act; struct sigaction act;
...@@ -143,15 +146,22 @@ int main(int argc, char *argv[]) ...@@ -143,15 +146,22 @@ int main(int argc, char *argv[])
i == SIGKILL) i == SIGKILL)
continue; continue;
sigfillset(&act.sa_mask); if (sigfillset(&act.sa_mask) ||
sigdelset(&act.sa_mask, SIGILL); sigdelset(&act.sa_mask, SIGILL) ||
sigdelset(&act.sa_mask, SIGSEGV); sigdelset(&act.sa_mask, SIGSEGV) ||
sigdelset(&act.sa_mask, SIGBUS); sigdelset(&act.sa_mask, SIGBUS) ||
sigdelset(&act.sa_mask, SIGSTOP); sigdelset(&act.sa_mask, SIGSTOP) ||
sigdelset(&act.sa_mask, SIGKILL); sigdelset(&act.sa_mask, SIGKILL)) {
ERROR("failed to set signal");
exit(EXIT_FAILURE);
}
act.sa_flags = 0; act.sa_flags = 0;
act.sa_handler = interrupt_handler; act.sa_handler = interrupt_handler;
sigaction(i, &act, NULL); if (sigaction(i, &act, NULL)) {
SYSERROR("failed to sigaction");
exit(EXIT_FAILURE);
}
} }
lxc_setup_fs(); lxc_setup_fs();
...@@ -170,7 +180,10 @@ int main(int argc, char *argv[]) ...@@ -170,7 +180,10 @@ int main(int argc, char *argv[])
for (i = 1; i < NSIG; i++) for (i = 1; i < NSIG; i++)
signal(i, SIG_DFL); signal(i, SIG_DFL);
sigprocmask(SIG_SETMASK, &omask, NULL); if (sigprocmask(SIG_SETMASK, &omask, NULL)) {
SYSERROR("failed to set signal mask");
exit(EXIT_FAILURE);
}
NOTICE("about to exec '%s'", aargv[0]); NOTICE("about to exec '%s'", aargv[0]);
...@@ -180,8 +193,11 @@ int main(int argc, char *argv[]) ...@@ -180,8 +193,11 @@ int main(int argc, char *argv[])
} }
/* let's process the signals now */ /* let's process the signals now */
sigdelset(&omask, SIGALRM); if (sigdelset(&omask, SIGALRM) ||
sigprocmask(SIG_SETMASK, &omask, NULL); sigprocmask(SIG_SETMASK, &omask, NULL)) {
SYSERROR("failed to set signal mask");
exit(EXIT_FAILURE);
}
/* no need of other inherited fds but stderr */ /* no need of other inherited fds but stderr */
close(fileno(stdin)); close(fileno(stdin));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment