X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fnspawn%2Fnspawn.c;h=8ce5fbeb629f6b25db1bd7cd0c297bf21c0e5067;hp=a9b9a3e062f7a6d0abd78660ab5c3e22bd3996b6;hb=c6c8f6e218995852350e5e35c080dec788c42c3f;hpb=4aab5d0cbd979b2cccb88534f118bceaa86466d8 diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index a9b9a3e06..8ce5fbeb6 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -23,27 +23,21 @@ #include #include #include -#include #include -#include #include #include #include #include #include #include -#include -#include #include #include -#include #include #include #include #include #include #include -#include #include #ifdef HAVE_SELINUX @@ -66,7 +60,6 @@ #include "util.h" #include "mkdir.h" #include "macro.h" -#include "audit.h" #include "missing.h" #include "cgroup-util.h" #include "strv.h" @@ -79,9 +72,7 @@ #include "bus-util.h" #include "bus-error.h" #include "ptyfwd.h" -#include "bus-kernel.h" #include "env-util.h" -#include "def.h" #include "rtnl-util.h" #include "udev-util.h" #include "blkid-util.h" @@ -190,6 +181,7 @@ static ExposePort *arg_expose_ports = NULL; static char **arg_property = NULL; static uid_t arg_uid_shift = UID_INVALID, arg_uid_range = 0x10000U; static bool arg_userns = false; +static int arg_kill_signal = 0; static void help(void) { printf("%s [OPTIONS...] [PATH] [ARGUMENTS...]\n\n" @@ -238,6 +230,7 @@ static void help(void) { " --capability=CAP In addition to the default, retain specified\n" " capability\n" " --drop-capability=CAP Drop the specified capability from the default set\n" + " --kill-signal=SIGNAL Select signal to use for shutting down PID 1\n" " --link-journal=MODE Link up guest journal, one of no, auto, guest, host,\n" " try-guest, try-host\n" " -j Equivalent to --link-journal=try-guest\n" @@ -302,6 +295,7 @@ static int parse_argv(int argc, char *argv[]) { ARG_TEMPLATE, ARG_PROPERTY, ARG_PRIVATE_USERS, + ARG_KILL_SIGNAL, }; static const struct option options[] = { @@ -341,6 +335,7 @@ static int parse_argv(int argc, char *argv[]) { { "port", required_argument, NULL, 'p' }, { "property", required_argument, NULL, ARG_PROPERTY }, { "private-users", optional_argument, NULL, ARG_PRIVATE_USERS }, + { "kill-signal", required_argument, NULL, ARG_KILL_SIGNAL }, {} }; @@ -776,6 +771,15 @@ static int parse_argv(int argc, char *argv[]) { arg_userns = true; break; + case ARG_KILL_SIGNAL: + arg_kill_signal = signal_from_string_try_harder(optarg); + if (arg_kill_signal < 0) { + log_error("Cannot parse signal: %s", optarg); + return -EINVAL; + } + + break; + case '?': return -EINVAL; @@ -838,6 +842,9 @@ static int parse_argv(int argc, char *argv[]) { arg_retain = (arg_retain | plus | (arg_private_network ? 1ULL << CAP_NET_ADMIN : 0)) & ~minus; + if (arg_boot && arg_kill_signal <= 0) + arg_kill_signal = SIGRTMIN+3; + return 1; } @@ -3568,7 +3575,7 @@ static int on_orderly_shutdown(sd_event_source *s, const struct signalfd_siginfo pid = PTR_TO_UINT32(userdata); if (pid > 0) { - if (kill(pid, SIGRTMIN+3) >= 0) { + if (kill(pid, arg_kill_signal) >= 0) { log_info("Trying to halt container. Send SIGTERM again to trigger immediate termination."); sd_event_source_set_userdata(s, NULL); return 0; @@ -4365,7 +4372,7 @@ int main(int argc, char *argv[]) { goto finish; } - if (arg_boot) { + if (arg_kill_signal > 0) { /* Try to kill the init system on SIGINT or SIGTERM */ sd_event_add_signal(event, NULL, SIGINT, on_orderly_shutdown, UINT32_TO_PTR(pid)); sd_event_add_signal(event, NULL, SIGTERM, on_orderly_shutdown, UINT32_TO_PTR(pid));