]> git.proxmox.com Git - mirror_lxc.git/commitdiff
lxc_init.c: error handing for sigaction and sigprocmask
authorQiang Huang <h.huangqiang@huawei.com>
Thu, 16 Jan 2014 07:30:01 +0000 (15:30 +0800)
committerStéphane Graber <stgraber@ubuntu.com>
Thu, 16 Jan 2014 16:04:07 +0000 (11:04 -0500)
Look through all LXC code and seems like only here are missed.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
src/lxc/lxc_init.c

index d88a935f557c8872a27befdd5985f23c86ae4f37..a59dd9c7c0dccaafb7ab533b3c1afaeb7f1cc698 100644 (file)
@@ -123,11 +123,14 @@ int main(int argc, char *argv[])
         * mask all the signals so we are safe to install a
         * signal handler and to fork
         */
-       sigfillset(&mask);
-       sigdelset(&mask, SIGILL);
-       sigdelset(&mask, SIGSEGV);
-       sigdelset(&mask, SIGBUS);
-       sigprocmask(SIG_SETMASK, &mask, &omask);
+       if (sigfillset(&mask) ||
+           sigdelset(&mask, SIGILL) ||
+           sigdelset(&mask, SIGSEGV) ||
+           sigdelset(&mask, SIGBUS) ||
+           sigprocmask(SIG_SETMASK, &mask, &omask)) {
+               SYSERROR("failed to set signal mask");
+               exit(EXIT_FAILURE);
+       }
 
        for (i = 1; i < NSIG; i++) {
                struct sigaction act;
@@ -143,15 +146,22 @@ int main(int argc, char *argv[])
                    i == SIGKILL)
                        continue;
 
-               sigfillset(&act.sa_mask);
-               sigdelset(&act.sa_mask, SIGILL);
-               sigdelset(&act.sa_mask, SIGSEGV);
-               sigdelset(&act.sa_mask, SIGBUS);
-               sigdelset(&act.sa_mask, SIGSTOP);
-               sigdelset(&act.sa_mask, SIGKILL);
+               if (sigfillset(&act.sa_mask) ||
+                   sigdelset(&act.sa_mask, SIGILL) ||
+                   sigdelset(&act.sa_mask, SIGSEGV) ||
+                   sigdelset(&act.sa_mask, SIGBUS) ||
+                   sigdelset(&act.sa_mask, SIGSTOP) ||
+                   sigdelset(&act.sa_mask, SIGKILL)) {
+                       ERROR("failed to set signal");
+                       exit(EXIT_FAILURE);
+               }
+
                act.sa_flags = 0;
                act.sa_handler = interrupt_handler;
-               sigaction(i, &act, NULL);
+               if (sigaction(i, &act, NULL)) {
+                       SYSERROR("failed to sigaction");
+                       exit(EXIT_FAILURE);
+               }
        }
 
        lxc_setup_fs();
@@ -170,7 +180,10 @@ int main(int argc, char *argv[])
                for (i = 1; i < NSIG; i++)
                        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]);
 
@@ -180,8 +193,11 @@ int main(int argc, char *argv[])
        }
 
        /* let's process the signals now */
-       sigdelset(&omask, SIGALRM);
-       sigprocmask(SIG_SETMASK, &omask, NULL);
+       if (sigdelset(&omask, SIGALRM) ||
+           sigprocmask(SIG_SETMASK, &omask, NULL)) {
+               SYSERROR("failed to set signal mask");
+               exit(EXIT_FAILURE);
+       }
 
        /* no need of other inherited fds but stderr */
        close(fileno(stdin));