]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/lxc_init.c
2 * lxc: linux Container library
4 * (C) Copyright IBM Corp. 2007, 2008
7 * Daniel Lezcano <dlezcano at fr.ibm.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <sys/types.h>
41 lxc_log_define(lxc_init
, lxc
);
45 static struct option options
[] = {
46 { "quiet", no_argument
, &quiet
, 1 },
50 static int was_interrupted
= 0;
52 int main(int argc
, char *argv
[])
55 void interrupt_handler(int sig
)
58 was_interrupted
= sig
;
69 int ret
= getopt_long_only(argc
, argv
, "", options
, NULL
);
82 if (lxc_log_init(NULL
, "none", 0, basename(argv
[0]), quiet
))
86 ERROR("missing command to launch");
90 aargv
= &argv
[optind
];
94 * mask all the signals so we are safe to install a
95 * signal handler and to fork
98 sigdelset(&mask
, SIGILL
);
99 sigdelset(&mask
, SIGSEGV
);
100 sigdelset(&mask
, SIGBUS
);
101 sigprocmask(SIG_SETMASK
, &mask
, &omask
);
103 for (i
= 1; i
< NSIG
; i
++) {
104 struct sigaction act
;
106 /* Exclude some signals: ILL, SEGV and BUS are likely to
107 * reveal a bug and we want a core. STOP and KILL cannot be
108 * handled anyway: they're here for documentation.
117 sigfillset(&act
.sa_mask
);
118 sigdelset(&act
.sa_mask
, SIGILL
);
119 sigdelset(&act
.sa_mask
, SIGSEGV
);
120 sigdelset(&act
.sa_mask
, SIGBUS
);
121 sigdelset(&act
.sa_mask
, SIGSTOP
);
122 sigdelset(&act
.sa_mask
, SIGKILL
);
124 act
.sa_handler
= interrupt_handler
;
125 sigaction(i
, &act
, NULL
);
131 if (lxc_caps_reset())
141 /* restore default signal handlers */
142 for (i
= 1; i
< NSIG
; i
++)
145 sigprocmask(SIG_SETMASK
, &omask
, NULL
);
147 NOTICE("about to exec '%s'", aargv
[0]);
149 execvp(aargv
[0], aargv
);
150 ERROR("failed to exec: '%s' : %m", aargv
[0]);
154 /* let's process the signals now */
155 sigdelset(&omask
, SIGALRM
);
156 sigprocmask(SIG_SETMASK
, &omask
, NULL
);
158 /* no need of other inherited fds but stderr */
159 close(fileno(stdin
));
160 close(fileno(stdout
));
168 switch (was_interrupted
) {
186 kill(pid
, was_interrupted
);
191 waited_pid
= wait(&status
);
192 if (waited_pid
< 0) {
198 ERROR("failed to wait child : %s",
203 /* reset timer each time a process exited */
208 * keep the exit code of started application
209 * (not wrapped pid) and continue to wait for
210 * the end of the orphan group.
212 if ((waited_pid
!= pid
) || (orphan
==1))
215 err
= lxc_error_set_and_log(waited_pid
, status
);