From: Lennart Poettering Date: Thu, 19 Jul 2012 21:47:10 +0000 (+0200) Subject: unit: split off KillContext from ExecContext containing only kill definitions X-Git-Tag: v187~5 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=4819ff0358b6317c195fd4b1768e03d09c871070 unit: split off KillContext from ExecContext containing only kill definitions --- diff --git a/Makefile.am b/Makefile.am index b15b9f54c..655d9bf6b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -455,6 +455,7 @@ MANPAGES = \ man/systemd.device.5 \ man/systemd.snapshot.5 \ man/systemd.exec.5 \ + man/systemd.kill.5 \ man/systemd.special.7 \ man/systemd.journal-fields.7 \ man/kernel-command-line.7 \ @@ -904,6 +905,8 @@ libsystemd_core_la_SOURCES = \ src/core/load-dropin.h \ src/core/execute.c \ src/core/execute.h \ + src/core/kill.c \ + src/core/kill.h \ src/core/dbus.c \ src/core/dbus.h \ src/core/dbus-manager.c \ @@ -932,6 +935,8 @@ libsystemd_core_la_SOURCES = \ src/core/dbus-device.h \ src/core/dbus-execute.c \ src/core/dbus-execute.h \ + src/core/dbus-kill.c \ + src/core/dbus-kill.h \ src/core/dbus-path.c \ src/core/dbus-path.h \ src/core/cgroup.c \ diff --git a/man/systemd.exec.xml b/man/systemd.exec.xml index 6e55d8dfc..e1193d2d5 100644 --- a/man/systemd.exec.xml +++ b/man/systemd.exec.xml @@ -1152,7 +1152,8 @@ systemd.service5, systemd.socket5, systemd.swap5, - systemd.mount5 + systemd.mount5, + systemd.kill5 diff --git a/man/systemd.kill.xml b/man/systemd.kill.xml new file mode 100644 index 000000000..330053404 --- /dev/null +++ b/man/systemd.kill.xml @@ -0,0 +1,170 @@ + + + + + + + + + systemd.kill + systemd + + + + Developer + Lennart + Poettering + lennart@poettering.net + + + + + + systemd.kill + 5 + + + + systemd.kill + Kill environment configuration + + + + systemd.service, + systemd.socket, + systemd.mount, + systemd.swap + + + + Description + + Unit configuration files for services, sockets, + mount points and swap devices share a subset of + configuration options which define the process killing + parameters of spawned processes. + + This man page lists the configuration options + shared by these four unit types. See + systemd.unit5 + for the common options of all unit configuration + files, and + systemd.service5, + systemd.socket5, + systemd.swap5 + and + systemd.mount5 + for more information on the specific unit + configuration files. The execution specific + configuration options are configured in the [Service], + [Socket], [Mount] resp. [Swap] section, depending on the unit + type. + + + + Options + + + + + KillMode= + Specifies how + processes of this service shall be + killed. One of + , + , + . + + If set to + all + remaining processes in the control + group of this unit will be terminated + on unit stop (for services: after the + stop command is executed, as + configured with + ExecStop=). If set + to only the + main process itself is killed. If set + to no process is + killed. In this case only the stop + command will be executed on unit + stop, but no process be killed + otherwise. Processes remaining alive + after stop are left in their control + group and the control group continues + to exist after stop unless it is + empty. Defaults to + . + + Processes will first be + terminated via SIGTERM (unless the + signal to send is changed via + KillSignal=). If + then after a delay (configured via the + TimeoutSec= option) + processes still remain, the + termination request is repeated with + the SIGKILL signal (unless this is + disabled via the + SendSIGKILL= + option). See + kill2 + for more + information. + + + + KillSignal= + Specifies which signal + to use when killing a + service. Defaults to SIGTERM. + + + + + SendSIGKILL= + Specifies whether to + send SIGKILL to remaining processes + after a timeout, if the normal + shutdown procedure left processes of + the service around. Takes a boolean + value. Defaults to "yes". + + + + + + + See Also + + systemd1, + systemctl8, + journalctl8, + systemd.unit5, + systemd.service5, + systemd.socket5, + systemd.swap5, + systemd.mount5, + systemd.exec5 + + + + diff --git a/man/systemd.mount.xml b/man/systemd.mount.xml index 105afb41e..bcaae3341 100644 --- a/man/systemd.mount.xml +++ b/man/systemd.mount.xml @@ -72,7 +72,10 @@ systemd.exec5, which define the execution environment the mount8 - binary is executed in. + binary is executed in, and in + systemd.kill5 + which define the way the processes are + terminated. Mount units must be named after the mount point directories they control. Example: the mount point @@ -147,7 +150,9 @@ supervises. A number of options that may be used in this section are shared with other unit types. These options are documented in - systemd.exec5. The + systemd.exec5 + and + systemd.kill5. The options specific to the [Mount] section of mount units are the following: @@ -220,50 +225,21 @@ will be terminated forcibly via SIGTERM, and after another delay of this time with SIGKILL. (See - below.) + in + systemd.kill5.) Takes a unit-less value in seconds, or a time span value such as "5min 20s". Pass 0 to disable the timeout logic. Defaults to 90s. - - - KillMode= - Specifies how - processes of this mount shall be - killed. One of - , - , - . - - This option is mostly equivalent - to the - option of service files. See - systemd.service5 - for details. - - - - KillSignal= - Specifies which signal - to use when killing a process of this - mount. Defaults to SIGTERM. - - - - - SendSIGKILL= - Specifies whether to - send SIGKILL to remaining processes - after a timeout, if the normal - shutdown procedure left processes of - the mount around. Takes a boolean - value. Defaults to "yes". - - - + + Check + systemd.exec5 + and + systemd.kill5 + for more settings. @@ -295,6 +271,7 @@ systemctl8, systemd.unit5, systemd.exec5, + systemd.kill5, systemd.service5, systemd.device5, mount8, diff --git a/man/systemd.service.xml b/man/systemd.service.xml index 38a4035f6..f43201dc7 100644 --- a/man/systemd.service.xml +++ b/man/systemd.service.xml @@ -72,7 +72,10 @@ Additional options are listed in systemd.exec5, which define the execution environment the commands - are executed in. + are executed in, and in + systemd.kill5 + which define the way the processes of the service are + terminated. Unless DefaultDependencies= is set to , service units will @@ -112,7 +115,9 @@ supervises. A number of options that may be used in this section are shared with other unit types. These options are documented in - systemd.exec5. The + systemd.exec5 + and + systemd.kill5. The options specific to the [Service] section of service units are the following: @@ -417,12 +422,13 @@ configured in this option are run are terminated according to the KillMode= setting - (see below). If this option is not - specified the process is terminated - right-away when service stop is - requested. Specifier and environment - variable substitution is supported - (including + (see + systemd.kill5). If + this option is not specified the + process is terminated right-away when + service stop is requested. Specifier + and environment variable substitution + is supported (including $MAINPID, see above). @@ -471,7 +477,7 @@ another delay of this time with SIGKILL. (See KillMode= - below.) Takes a unit-less value in seconds, or a + in systemd.kill5) Takes a unit-less value in seconds, or a time span value such as "5min 20s". Pass 0 to disable the timeout logic. Defaults to @@ -598,72 +604,6 @@ false. - - KillMode= - Specifies how - processes of this service shall be - killed. One of - , - , - . - - If set to - all - remaining processes in the control - group of this service will be - terminated on service stop, after the - stop command (as configured with - ExecStop=) is - executed. If set to - only the main - process itself is killed. If set to - no process is - killed. In this case only the stop - command will be executed on service - stop, but no process be killed - otherwise. Processes remaining alive - after stop are left in their control - group and the control group continues - to exist after stop unless it is - empty. Defaults to - . - - Processes will first be - terminated via SIGTERM (unless the - signal to send is changed via - KillSignal=). If - then after a delay (configured via the - TimeoutSec= option) - processes still remain, the - termination request is repeated with - the SIGKILL signal (unless this is - disabled via the - SendSIGKILL= - option). See - kill2 - for more - information. - - - - KillSignal= - Specifies which signal - to use when killing a - service. Defaults to SIGTERM. - - - - - SendSIGKILL= - Specifies whether to - send SIGKILL to remaining processes - after a timeout, if the normal - shutdown procedure left processes of - the service around. Takes a boolean - value. Defaults to "yes". - - - NonBlocking= Set O_NONBLOCK flag @@ -818,6 +758,13 @@ + + Check + systemd.exec5 + and + systemd.kill5 + for more settings. + @@ -888,7 +835,8 @@ systemd1, systemctl8, systemd.unit5, - systemd.exec5 + systemd.exec5, + systemd.kill5 diff --git a/man/systemd.socket.xml b/man/systemd.socket.xml index 5ca1c7a7c..8a12e25cf 100644 --- a/man/systemd.socket.xml +++ b/man/systemd.socket.xml @@ -76,7 +76,10 @@ , and commands are executed - in. + in, and in + systemd.kill5 + which define the way the processes are + terminated. For each socket file a matching service file (see @@ -134,7 +137,9 @@ supervises. A number of options that may be used in this section are shared with other unit types. These options are documented in - systemd.exec5. The + systemd.exec5 + and + systemd.kill5. The options specific to the [Socket] section of socket units are the following: @@ -603,7 +608,7 @@ will be terminated forcibly via SIGTERM, and after another delay of this time with SIGKILL. (See - below.) + in systemd.kill5.) Takes a unit-less value in seconds, or a time span value such as "5min 20s". Pass 0 to disable the timeout @@ -611,41 +616,6 @@ 90s. - - KillMode= - Specifies how - processes of this socket unit shall be - killed. One of - , - , - . - - This option is mostly equivalent - to the - option of service files. See - systemd.service5 - for details. - - - - KillSignal= - Specifies which signal - to use when killing a process of this - socket. Defaults to SIGTERM. - - - - - SendSIGKILL= - Specifies whether to - send SIGKILL to remaining processes - after a timeout, if the normal - shutdown procedure left processes of - the socket around. Takes a boolean - value. Defaults to "yes". - - - Service= Specifies the service @@ -658,6 +628,13 @@ + + Check + systemd.exec5 + and + systemd.kill5 + for more settings. + @@ -667,6 +644,7 @@ systemctl8, systemd.unit5, systemd.exec5, + systemd.kill5, systemd.service5 diff --git a/man/systemd.swap.xml b/man/systemd.swap.xml index aaf77f839..5eb008dfc 100644 --- a/man/systemd.swap.xml +++ b/man/systemd.swap.xml @@ -68,6 +68,15 @@ specific configuration options are configured in the [Swap] section. + Additional options are listed in + systemd.exec5, + which define the execution environment the + swapon8 + binary is executed in, and in + systemd.kill5 + which define the way the processes are + terminated. + Swap units must be named after the devices (resp. files) they control. Example: the swap device /dev/sda5 must be configured in a @@ -121,7 +130,9 @@ supervises. A number of options that may be used in this section are shared with other unit types. These options are documented in - systemd.exec5. The + systemd.exec5 + and + systemd.kill5. The options specific to the [Swap] section of swap units are the following: @@ -167,49 +178,21 @@ will be terminated forcibly via SIGTERM, and after another delay of this time with SIGKILL. (See - below.) + in + systemd.kill5.) Takes a unit-less value in seconds, or a time span value such as "5min 20s". Pass 0 to disable the timeout logic. Defaults to 90s. - - - KillMode= - Specifies how - processes of this swap shall be - killed. One of - , - , - . - - This option is mostly equivalent - to the - option of service files. See - systemd.service5 - for details. - - - - KillSignal= - Specifies which signal - to use when killing a process of this - swap. Defaults to SIGTERM. - - - - - SendSIGKILL= - Specifies whether to - send SIGKILL to remaining processes - after a timeout, if the normal - shutdown procedure left processes of - the swap around. Takes a boolean - value. Defaults to "yes". - - + + Check + systemd.exec5 + and + systemd.kill5 + for more settings. @@ -219,6 +202,7 @@ systemctl8, systemd.unit5, systemd.exec5, + systemd.kill5, systemd.device5, systemd.mount5, swapon8, diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index a00ad5079..e815cb58e 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -30,8 +30,6 @@ #include "dbus-common.h" #include "syscall-list.h" -DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_execute_append_kill_mode, kill_mode, KillMode); - DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_execute_append_input, exec_input, ExecInput); DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_execute_append_output, exec_output, ExecOutput); @@ -431,8 +429,6 @@ const BusProperty bus_exec_context_properties[] = { { "PrivateTmp", bus_property_append_bool, "b", offsetof(ExecContext, private_tmp) }, { "PrivateNetwork", bus_property_append_bool, "b", offsetof(ExecContext, private_network) }, { "SameProcessGroup", bus_property_append_bool, "b", offsetof(ExecContext, same_pgrp) }, - { "KillMode", bus_execute_append_kill_mode, "s", offsetof(ExecContext, kill_mode) }, - { "KillSignal", bus_property_append_int, "i", offsetof(ExecContext, kill_signal) }, { "UtmpIdentifier", bus_property_append_string, "s", offsetof(ExecContext, utmp_id), true }, { "ControlGroupModify", bus_property_append_bool, "b", offsetof(ExecContext, control_group_modify) }, { "ControlGroupPersistent", bus_property_append_tristate_false, "b", offsetof(ExecContext, control_group_persistent) }, diff --git a/src/core/dbus-execute.h b/src/core/dbus-execute.h index feb883335..eaa1b73e6 100644 --- a/src/core/dbus-execute.h +++ b/src/core/dbus-execute.h @@ -120,6 +120,5 @@ int bus_execute_append_capabilities(DBusMessageIter *i, const char *property, vo int bus_execute_append_capability_bs(DBusMessageIter *i, const char *property, void *data); int bus_execute_append_rlimits(DBusMessageIter *i, const char *property, void *data); int bus_execute_append_command(DBusMessageIter *u, const char *property, void *data); -int bus_execute_append_kill_mode(DBusMessageIter *i, const char *property, void *data); int bus_execute_append_env_files(DBusMessageIter *i, const char *property, void *data); int bus_execute_append_syscall_filter(DBusMessageIter *i, const char *property, void *data); diff --git a/src/core/dbus-kill.c b/src/core/dbus-kill.c new file mode 100644 index 000000000..165f63074 --- /dev/null +++ b/src/core/dbus-kill.c @@ -0,0 +1,35 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2012 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ + +#include +#include + +#include "dbus-kill.h" +#include "dbus-common.h" + +DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_kill_append_mode, kill_mode, KillMode); + +const BusProperty bus_kill_context_properties[] = { + { "KillMode", bus_kill_append_mode, "s", offsetof(KillContext, kill_mode) }, + { "KillSignal", bus_property_append_int, "i", offsetof(KillContext, kill_signal) }, + { "SendSIGKILL", bus_property_append_bool, "b", offsetof(KillContext, send_sigkill) }, + { NULL, } +}; diff --git a/src/core/dbus-kill.h b/src/core/dbus-kill.h new file mode 100644 index 000000000..238fbd36d --- /dev/null +++ b/src/core/dbus-kill.h @@ -0,0 +1,39 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2012 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ + +#include + +#include "manager.h" +#include "dbus-common.h" + +#define BUS_KILL_CONTEXT_INTERFACE \ + " \n" \ + " \n" \ + " \n" + +#define BUS_KILL_COMMAND_INTERFACE(name) \ + " \n" + +extern const BusProperty bus_kill_context_properties[]; + +int bus_kill_append_mode(DBusMessageIter *i, const char *property, void *data); diff --git a/src/core/dbus-mount.c b/src/core/dbus-mount.c index 26b04abe5..93bfa4c35 100644 --- a/src/core/dbus-mount.c +++ b/src/core/dbus-mount.c @@ -23,6 +23,7 @@ #include "dbus-unit.h" #include "dbus-mount.h" +#include "dbus-kill.h" #include "dbus-execute.h" #include "dbus-common.h" @@ -37,6 +38,7 @@ BUS_EXEC_COMMAND_INTERFACE("ExecUnmount") \ BUS_EXEC_COMMAND_INTERFACE("ExecRemount") \ BUS_EXEC_CONTEXT_INTERFACE \ + BUS_KILL_CONTEXT_INTERFACE \ " \n" \ " \n" \ " \n" \ @@ -155,6 +157,7 @@ DBusHandlerResult bus_mount_message_handler(Unit *u, DBusConnection *c, DBusMess { "org.freedesktop.systemd1.Unit", bus_unit_properties, u }, { "org.freedesktop.systemd1.Mount", bus_mount_properties, m }, { "org.freedesktop.systemd1.Mount", bus_exec_context_properties, &m->exec_context }, + { "org.freedesktop.systemd1.Mount", bus_kill_context_properties, &m->kill_context }, { NULL, } }; diff --git a/src/core/dbus-service.c b/src/core/dbus-service.c index 6568cd5ce..c0fac16d2 100644 --- a/src/core/dbus-service.c +++ b/src/core/dbus-service.c @@ -23,6 +23,7 @@ #include "dbus-unit.h" #include "dbus-execute.h" +#include "dbus-kill.h" #include "dbus-service.h" #include "dbus-common.h" @@ -47,6 +48,7 @@ BUS_EXEC_COMMAND_INTERFACE("ExecStop") \ BUS_EXEC_COMMAND_INTERFACE("ExecStopPost") \ BUS_EXEC_CONTEXT_INTERFACE \ + BUS_KILL_CONTEXT_INTERFACE \ " \n" \ " \n" \ " \n" \ @@ -140,10 +142,12 @@ static const BusProperty bus_service_properties[] = { DBusHandlerResult bus_service_message_handler(Unit *u, DBusConnection *connection, DBusMessage *message) { Service *s = SERVICE(u); + const BusBoundProperties bps[] = { { "org.freedesktop.systemd1.Unit", bus_unit_properties, u }, { "org.freedesktop.systemd1.Service", bus_service_properties, s }, { "org.freedesktop.systemd1.Service", bus_exec_context_properties, &s->exec_context }, + { "org.freedesktop.systemd1.Service", bus_kill_context_properties, &s->kill_context }, { "org.freedesktop.systemd1.Service", bus_exec_main_status_properties, &s->main_exec_status }, { NULL, } }; diff --git a/src/core/dbus-socket.c b/src/core/dbus-socket.c index 80d19dd1b..b2045225d 100644 --- a/src/core/dbus-socket.c +++ b/src/core/dbus-socket.c @@ -24,6 +24,7 @@ #include "dbus-unit.h" #include "dbus-socket.h" #include "dbus-execute.h" +#include "dbus-kill.h" #include "dbus-common.h" #define BUS_SOCKET_INTERFACE \ @@ -36,6 +37,7 @@ BUS_EXEC_COMMAND_INTERFACE("ExecStopPre") \ BUS_EXEC_COMMAND_INTERFACE("ExecStopPost") \ BUS_EXEC_CONTEXT_INTERFACE \ + BUS_KILL_CONTEXT_INTERFACE \ " \n" \ " \n" \ " \n" \ @@ -132,6 +134,7 @@ DBusHandlerResult bus_socket_message_handler(Unit *u, DBusConnection *c, DBusMes { "org.freedesktop.systemd1.Unit", bus_unit_properties, u }, { "org.freedesktop.systemd1.Socket", bus_socket_properties, s }, { "org.freedesktop.systemd1.Socket", bus_exec_context_properties, &s->exec_context }, + { "org.freedesktop.systemd1.Socket", bus_kill_context_properties, &s->kill_context }, { NULL, } }; diff --git a/src/core/dbus-swap.c b/src/core/dbus-swap.c index 3ede0e606..cad6ec1aa 100644 --- a/src/core/dbus-swap.c +++ b/src/core/dbus-swap.c @@ -25,6 +25,7 @@ #include "dbus-unit.h" #include "dbus-swap.h" #include "dbus-execute.h" +#include "dbus-kill.h" #include "dbus-common.h" #define BUS_SWAP_INTERFACE \ @@ -35,6 +36,7 @@ BUS_EXEC_COMMAND_INTERFACE("ExecActivate") \ BUS_EXEC_COMMAND_INTERFACE("ExecDeactivate") \ BUS_EXEC_CONTEXT_INTERFACE \ + BUS_KILL_CONTEXT_INTERFACE \ " \n" \ " \n" \ " \n" @@ -102,6 +104,7 @@ DBusHandlerResult bus_swap_message_handler(Unit *u, DBusConnection *c, DBusMessa { "org.freedesktop.systemd1.Unit", bus_unit_properties, u }, { "org.freedesktop.systemd1.Swap", bus_swap_properties, s }, { "org.freedesktop.systemd1.Swap", bus_exec_context_properties, &s->exec_context }, + { "org.freedesktop.systemd1.Swap", bus_kill_context_properties, &s->kill_context }, { NULL, } }; diff --git a/src/core/execute.c b/src/core/execute.c index db4a8ae51..fc0edc6cf 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -1541,8 +1541,6 @@ void exec_context_init(ExecContext *c) { c->syslog_priority = LOG_DAEMON|LOG_INFO; c->syslog_level_prefix = true; c->mount_flags = MS_SHARED; - c->kill_signal = SIGTERM; - c->send_sigkill = true; c->control_group_persistent = -1; c->ignore_sigpipe = true; c->timer_slack_nsec = (nsec_t) -1; @@ -1735,7 +1733,8 @@ void exec_context_dump(ExecContext *c, FILE* f, const char *prefix) { "%sPrivateTmp: %s\n" "%sControlGroupModify: %s\n" "%sControlGroupPersistent: %s\n" - "%sPrivateNetwork: %s\n", + "%sPrivateNetwork: %s\n" + "%sIgnoreSIGPIPE: %s\n", prefix, c->umask, prefix, c->working_directory ? c->working_directory : "/", prefix, c->root_directory ? c->root_directory : "/", @@ -1743,7 +1742,8 @@ void exec_context_dump(ExecContext *c, FILE* f, const char *prefix) { prefix, yes_no(c->private_tmp), prefix, yes_no(c->control_group_modify), prefix, yes_no(c->control_group_persistent), - prefix, yes_no(c->private_network)); + prefix, yes_no(c->private_network), + prefix, yes_no(c->ignore_sigpipe)); STRV_FOREACH(e, c->environment) fprintf(f, "%sEnvironment: %s\n", prefix, *e); @@ -1894,16 +1894,6 @@ void exec_context_dump(ExecContext *c, FILE* f, const char *prefix) { fputs("\n", f); } - fprintf(f, - "%sKillMode: %s\n" - "%sKillSignal: SIG%s\n" - "%sSendSIGKILL: %s\n" - "%sIgnoreSIGPIPE: %s\n", - prefix, kill_mode_to_string(c->kill_mode), - prefix, signal_to_string(c->kill_signal), - prefix, yes_no(c->send_sigkill), - prefix, yes_no(c->ignore_sigpipe)); - if (c->utmp_id) fprintf(f, "%sUtmpIdentifier: %s\n", @@ -2111,19 +2101,3 @@ static const char* const exec_output_table[_EXEC_OUTPUT_MAX] = { }; DEFINE_STRING_TABLE_LOOKUP(exec_output, ExecOutput); - -static const char* const kill_mode_table[_KILL_MODE_MAX] = { - [KILL_CONTROL_GROUP] = "control-group", - [KILL_PROCESS] = "process", - [KILL_NONE] = "none" -}; - -DEFINE_STRING_TABLE_LOOKUP(kill_mode, KillMode); - -static const char* const kill_who_table[_KILL_WHO_MAX] = { - [KILL_MAIN] = "main", - [KILL_CONTROL] = "control", - [KILL_ALL] = "all" -}; - -DEFINE_STRING_TABLE_LOOKUP(kill_who, KillWho); diff --git a/src/core/execute.h b/src/core/execute.h index 09f246e16..2bcd2e1e6 100644 --- a/src/core/execute.h +++ b/src/core/execute.h @@ -39,22 +39,6 @@ struct CGroupAttribute; #include "list.h" #include "util.h" -typedef enum KillMode { - KILL_CONTROL_GROUP = 0, - KILL_PROCESS, - KILL_NONE, - _KILL_MODE_MAX, - _KILL_MODE_INVALID = -1 -} KillMode; - -typedef enum KillWho { - KILL_MAIN, - KILL_CONTROL, - KILL_ALL, - _KILL_WHO_MAX, - _KILL_WHO_INVALID = -1 -} KillWho; - typedef enum ExecInput { EXEC_INPUT_NULL, EXEC_INPUT_TTY, @@ -146,11 +130,6 @@ struct ExecContext { uint64_t capability_bounding_set_drop; - /* Not relevant for spawning processes, just for killing */ - KillMode kill_mode; - int kill_signal; - bool send_sigkill; - cap_t capabilities; int secure_bits; @@ -228,9 +207,3 @@ ExecOutput exec_output_from_string(const char *s); const char* exec_input_to_string(ExecInput i); ExecInput exec_input_from_string(const char *s); - -const char *kill_mode_to_string(KillMode k); -KillMode kill_mode_from_string(const char *s); - -const char *kill_who_to_string(KillWho k); -KillWho kill_who_from_string(const char *s); diff --git a/src/core/kill.c b/src/core/kill.c new file mode 100644 index 000000000..0775653f7 --- /dev/null +++ b/src/core/kill.c @@ -0,0 +1,63 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2012 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ + +#include + +#include "kill.h" +#include "util.h" + +void kill_context_init(KillContext *c) { + assert(c); + + c->kill_signal = SIGTERM; + c->send_sigkill = true; +} + +void kill_context_dump(KillContext *c, FILE *f, const char *prefix) { + assert(c); + + if (!prefix) + prefix = ""; + + fprintf(f, + "%sKillMode: %s\n" + "%sKillSignal: SIG%s\n" + "%sSendSIGKILL: %s\n", + prefix, kill_mode_to_string(c->kill_mode), + prefix, signal_to_string(c->kill_signal), + prefix, yes_no(c->send_sigkill)); +} + +static const char* const kill_mode_table[_KILL_MODE_MAX] = { + [KILL_CONTROL_GROUP] = "control-group", + [KILL_PROCESS] = "process", + [KILL_NONE] = "none" +}; + +DEFINE_STRING_TABLE_LOOKUP(kill_mode, KillMode); + +static const char* const kill_who_table[_KILL_WHO_MAX] = { + [KILL_MAIN] = "main", + [KILL_CONTROL] = "control", + [KILL_ALL] = "all" +}; + +DEFINE_STRING_TABLE_LOOKUP(kill_who, KillWho); diff --git a/src/core/kill.h b/src/core/kill.h new file mode 100644 index 000000000..4f8823927 --- /dev/null +++ b/src/core/kill.h @@ -0,0 +1,58 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2012 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ + +typedef struct KillContext KillContext; + +#include +#include + +typedef enum KillMode { + KILL_CONTROL_GROUP = 0, + KILL_PROCESS, + KILL_NONE, + _KILL_MODE_MAX, + _KILL_MODE_INVALID = -1 +} KillMode; + +struct KillContext { + KillMode kill_mode; + int kill_signal; + bool send_sigkill; +}; + +typedef enum KillWho { + KILL_MAIN, + KILL_CONTROL, + KILL_ALL, + _KILL_WHO_MAX, + _KILL_WHO_INVALID = -1 +} KillWho; + +void kill_context_init(KillContext *c); +void kill_context_dump(KillContext *c, FILE *f, const char *prefix); + +const char *kill_mode_to_string(KillMode k); +KillMode kill_mode_from_string(const char *s); + +const char *kill_who_to_string(KillWho k); +KillWho kill_who_from_string(const char *s); diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4 index 140cb9c0a..d6a4711a3 100644 --- a/src/core/load-fragment-gperf.gperf.m4 +++ b/src/core/load-fragment-gperf.gperf.m4 @@ -84,14 +84,16 @@ $1.PrivateNetwork, config_parse_bool, 0, $1.MountFlags, config_parse_exec_mount_flags, 0, offsetof($1, exec_context) $1.TCPWrapName, config_parse_unit_string_printf, 0, offsetof($1, exec_context.tcpwrap_name) $1.PAMName, config_parse_unit_string_printf, 0, offsetof($1, exec_context.pam_name) -$1.KillMode, config_parse_kill_mode, 0, offsetof($1, exec_context.kill_mode) -$1.KillSignal, config_parse_kill_signal, 0, offsetof($1, exec_context.kill_signal) -$1.SendSIGKILL, config_parse_bool, 0, offsetof($1, exec_context.send_sigkill) $1.IgnoreSIGPIPE, config_parse_bool, 0, offsetof($1, exec_context.ignore_sigpipe) $1.UtmpIdentifier, config_parse_unit_string_printf, 0, offsetof($1, exec_context.utmp_id) $1.ControlGroupModify, config_parse_bool, 0, offsetof($1, exec_context.control_group_modify) $1.ControlGroupPersistent, config_parse_tristate, 0, offsetof($1, exec_context.control_group_persistent)' )m4_dnl +m4_define(`KILL_CONTEXT_CONFIG_ITEMS', +`$1.SendSIGKILL, config_parse_bool, 0, offsetof($1, kill_context.send_sigkill) +$1.KillMode, config_parse_kill_mode, 0, offsetof($1, kill_context.kill_mode) +$1.KillSignal, config_parse_kill_signal, 0, offsetof($1, kill_context.kill_signal)' +)m4_dnl Unit.Description, config_parse_unit_string_printf, 0, offsetof(Unit, description) Unit.Documentation, config_parse_documentation, 0, offsetof(Unit, documentation) Unit.SourcePath, config_parse_path, 0, offsetof(Unit, source_path) @@ -162,6 +164,7 @@ Service.NotifyAccess, config_parse_notify_access, 0, Service.Sockets, config_parse_service_sockets, 0, 0 Service.FsckPassNo, config_parse_fsck_passno, 0, offsetof(Service, fsck_passno) EXEC_CONTEXT_CONFIG_ITEMS(Service)m4_dnl +KILL_CONTEXT_CONFIG_ITEMS(Service)m4_dnl m4_dnl Socket.ListenStream, config_parse_socket_listen, 0, 0 Socket.ListenDatagram, config_parse_socket_listen, 0, 0 @@ -200,6 +203,7 @@ Socket.MessageQueueMaxMessages, config_parse_long, 0, Socket.MessageQueueMessageSize, config_parse_long, 0, offsetof(Socket, mq_msgsize) Socket.Service, config_parse_socket_service, 0, 0 EXEC_CONTEXT_CONFIG_ITEMS(Socket)m4_dnl +KILL_CONTEXT_CONFIG_ITEMS(Socket)m4_dnl m4_dnl Mount.What, config_parse_string, 0, offsetof(Mount, parameters_fragment.what) Mount.Where, config_parse_path, 0, offsetof(Mount, where) @@ -209,6 +213,7 @@ Mount.FsckPassNo, config_parse_fsck_passno, 0, Mount.TimeoutSec, config_parse_usec, 0, offsetof(Mount, timeout_usec) Mount.DirectoryMode, config_parse_mode, 0, offsetof(Mount, directory_mode) EXEC_CONTEXT_CONFIG_ITEMS(Mount)m4_dnl +KILL_CONTEXT_CONFIG_ITEMS(Mount)m4_dnl m4_dnl Automount.Where, config_parse_path, 0, offsetof(Automount, where) Automount.DirectoryMode, config_parse_mode, 0, offsetof(Automount, directory_mode) @@ -217,6 +222,7 @@ Swap.What, config_parse_path, 0, Swap.Priority, config_parse_int, 0, offsetof(Swap, parameters_fragment.priority) Swap.TimeoutSec, config_parse_usec, 0, offsetof(Swap, timeout_usec) EXEC_CONTEXT_CONFIG_ITEMS(Swap)m4_dnl +KILL_CONTEXT_CONFIG_ITEMS(Swap)m4_dnl m4_dnl Timer.OnActiveSec, config_parse_timer, 0, 0 Timer.OnBootSec, config_parse_timer, 0, 0 diff --git a/src/core/mount.c b/src/core/mount.c index a88b25587..82c64ff79 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -79,6 +79,8 @@ static void mount_init(Unit *u) { m->exec_context.std_error = u->manager->default_std_error; } + kill_context_init(&m->kill_context); + /* We need to make sure that /bin/mount is always called in * the same process group as us, so that the autofs kernel * side doesn't send us another mount request while we are @@ -529,7 +531,7 @@ static int mount_verify(Mount *m) { return -EBADMSG; } - if (m->exec_context.pam_name && m->exec_context.kill_mode != KILL_CONTROL_GROUP) { + if (m->exec_context.pam_name && m->kill_context.kill_mode != KILL_CONTROL_GROUP) { log_error("%s has PAM enabled. Kill mode must be set to 'control-group'. Refusing.", UNIT(m)->id); return -EINVAL; } @@ -783,6 +785,7 @@ static void mount_dump(Unit *u, FILE *f, const char *prefix) { prefix, (unsigned long) m->control_pid); exec_context_dump(&m->exec_context, f, prefix); + kill_context_dump(&m->kill_context, f, prefix); } static int mount_spawn(Mount *m, ExecCommand *c, pid_t *_pid) { @@ -855,10 +858,10 @@ static void mount_enter_signal(Mount *m, MountState state, MountResult f) { if (f != MOUNT_SUCCESS) m->result = f; - if (m->exec_context.kill_mode != KILL_NONE) { + if (m->kill_context.kill_mode != KILL_NONE) { int sig = (state == MOUNT_MOUNTING_SIGTERM || state == MOUNT_UNMOUNTING_SIGTERM || - state == MOUNT_REMOUNTING_SIGTERM) ? m->exec_context.kill_signal : SIGKILL; + state == MOUNT_REMOUNTING_SIGTERM) ? m->kill_context.kill_signal : SIGKILL; if (m->control_pid > 0) { if (kill_and_sigcont(m->control_pid, sig) < 0 && errno != ESRCH) @@ -868,7 +871,7 @@ static void mount_enter_signal(Mount *m, MountState state, MountResult f) { wait_for_exit = true; } - if (m->exec_context.kill_mode == KILL_CONTROL_GROUP) { + if (m->kill_context.kill_mode == KILL_CONTROL_GROUP) { if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func))) { r = -ENOMEM; @@ -1327,7 +1330,7 @@ static void mount_timer_event(Unit *u, uint64_t elapsed, Watch *w) { break; case MOUNT_MOUNTING_SIGTERM: - if (m->exec_context.send_sigkill) { + if (m->kill_context.send_sigkill) { log_warning("%s mounting timed out. Killing.", u->id); mount_enter_signal(m, MOUNT_MOUNTING_SIGKILL, MOUNT_FAILURE_TIMEOUT); } else { @@ -1341,7 +1344,7 @@ static void mount_timer_event(Unit *u, uint64_t elapsed, Watch *w) { break; case MOUNT_REMOUNTING_SIGTERM: - if (m->exec_context.send_sigkill) { + if (m->kill_context.send_sigkill) { log_warning("%s remounting timed out. Killing.", u->id); mount_enter_signal(m, MOUNT_REMOUNTING_SIGKILL, MOUNT_FAILURE_TIMEOUT); } else { @@ -1355,7 +1358,7 @@ static void mount_timer_event(Unit *u, uint64_t elapsed, Watch *w) { break; case MOUNT_UNMOUNTING_SIGTERM: - if (m->exec_context.send_sigkill) { + if (m->kill_context.send_sigkill) { log_warning("%s unmounting timed out. Killing.", u->id); mount_enter_signal(m, MOUNT_UNMOUNTING_SIGKILL, MOUNT_FAILURE_TIMEOUT); } else { diff --git a/src/core/mount.h b/src/core/mount.h index 9583eebe3..67d6132a5 100644 --- a/src/core/mount.h +++ b/src/core/mount.h @@ -24,6 +24,7 @@ typedef struct Mount Mount; #include "unit.h" +#include "kill.h" typedef enum MountState { MOUNT_DEAD, @@ -95,6 +96,7 @@ struct Mount { ExecCommand exec_command[_MOUNT_EXEC_COMMAND_MAX]; ExecContext exec_context; + KillContext kill_context; MountState state, deserialized_state; diff --git a/src/core/service.c b/src/core/service.c index 5dc06b36c..567e9a4eb 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -153,6 +153,7 @@ static void service_init(Unit *u) { for (i = 0; i < RLIMIT_NLIMITS; i++) if (UNIT(s)->manager->rlimit[i]) s->exec_context.rlimit[i] = newdup(struct rlimit, UNIT(s)->manager->rlimit[i], 1); + kill_context_init(&s->kill_context); RATELIMIT_INIT(s->start_limit, 10*USEC_PER_SEC, 5); @@ -928,7 +929,7 @@ static int service_load_sysv_path(Service *s, const char *path) { s->guess_main_pid = false; s->restart = SERVICE_RESTART_NO; s->exec_context.ignore_sigpipe = false; - s->exec_context.kill_mode = KILL_PROCESS; + s->kill_context.kill_mode = KILL_PROCESS; /* We use the long description only if * no short description is set. */ @@ -1164,7 +1165,7 @@ static int service_verify(Service *s) { if (s->bus_name && s->type != SERVICE_DBUS) log_warning("%s has a D-Bus service name specified, but is not of type dbus. Ignoring.", UNIT(s)->id); - if (s->exec_context.pam_name && s->exec_context.kill_mode != KILL_CONTROL_GROUP) { + if (s->exec_context.pam_name && s->kill_context.kill_mode != KILL_CONTROL_GROUP) { log_error("%s has PAM enabled. Kill mode must be set to 'control-group'. Refusing.", UNIT(s)->id); return -EINVAL; } @@ -1351,6 +1352,7 @@ static void service_dump(Unit *u, FILE *f, const char *prefix) { prefix, s->bus_name, prefix, yes_no(s->bus_name_good)); + kill_context_dump(&s->kill_context, f, prefix); exec_context_dump(&s->exec_context, f, prefix); for (c = 0; c < _SERVICE_EXEC_COMMAND_MAX; c++) { @@ -1967,8 +1969,8 @@ static void service_enter_signal(Service *s, ServiceState state, ServiceResult f if (f != SERVICE_SUCCESS) s->result = f; - if (s->exec_context.kill_mode != KILL_NONE) { - int sig = (state == SERVICE_STOP_SIGTERM || state == SERVICE_FINAL_SIGTERM) ? s->exec_context.kill_signal : SIGKILL; + if (s->kill_context.kill_mode != KILL_NONE) { + int sig = (state == SERVICE_STOP_SIGTERM || state == SERVICE_FINAL_SIGTERM) ? s->kill_context.kill_signal : SIGKILL; if (s->main_pid > 0) { if (kill_and_sigcont(s->main_pid, sig) < 0 && errno != ESRCH) @@ -1984,9 +1986,10 @@ static void service_enter_signal(Service *s, ServiceState state, ServiceResult f wait_for_exit = true; } - if (s->exec_context.kill_mode == KILL_CONTROL_GROUP) { + if (s->kill_context.kill_mode == KILL_CONTROL_GROUP) { - if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func))) { + pid_set = set_new(trivial_hash_func, trivial_compare_func); + if (!pid_set) { r = -ENOMEM; goto fail; } @@ -3144,7 +3147,7 @@ static void service_timer_event(Unit *u, uint64_t elapsed, Watch* w) { break; case SERVICE_STOP_SIGTERM: - if (s->exec_context.send_sigkill) { + if (s->kill_context.send_sigkill) { log_warning("%s stopping timed out. Killing.", u->id); service_enter_signal(s, SERVICE_STOP_SIGKILL, SERVICE_FAILURE_TIMEOUT); } else { @@ -3169,7 +3172,7 @@ static void service_timer_event(Unit *u, uint64_t elapsed, Watch* w) { break; case SERVICE_FINAL_SIGTERM: - if (s->exec_context.send_sigkill) { + if (s->kill_context.send_sigkill) { log_warning("%s stopping timed out (2). Killing.", u->id); service_enter_signal(s, SERVICE_FINAL_SIGKILL, SERVICE_FAILURE_TIMEOUT); } else { diff --git a/src/core/service.h b/src/core/service.h index 5ad09d0ac..cc63347c7 100644 --- a/src/core/service.h +++ b/src/core/service.h @@ -27,6 +27,7 @@ typedef struct Service Service; #include "path.h" #include "ratelimit.h" #include "service.h" +#include "kill.h" typedef enum ServiceState { SERVICE_DEAD, @@ -126,7 +127,9 @@ struct Service { Watch watchdog_watch; ExecCommand* exec_command[_SERVICE_EXEC_COMMAND_MAX]; + ExecContext exec_context; + KillContext kill_context; ServiceState state, deserialized_state; diff --git a/src/core/socket.c b/src/core/socket.c index 8153a8e76..6d417878b 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -83,6 +83,7 @@ static void socket_init(Unit *u) { exec_context_init(&s->exec_context); s->exec_context.std_output = u->manager->default_std_output; s->exec_context.std_error = u->manager->default_std_error; + kill_context_init(&s->kill_context); s->control_command_id = _SOCKET_EXEC_COMMAND_INVALID; } @@ -223,7 +224,7 @@ static int socket_verify(Socket *s) { return -EINVAL; } - if (s->exec_context.pam_name && s->exec_context.kill_mode != KILL_CONTROL_GROUP) { + if (s->exec_context.pam_name && s->kill_context.kill_mode != KILL_CONTROL_GROUP) { log_error("%s has PAM enabled. Kill mode must be set to 'control-group'. Refusing.", UNIT(s)->id); return -EINVAL; } @@ -526,6 +527,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) { } exec_context_dump(&s->exec_context, f, prefix); + kill_context_dump(&s->kill_context, f, prefix); for (c = 0; c < _SOCKET_EXEC_COMMAND_MAX; c++) { if (!s->exec_command[c]) @@ -1226,8 +1228,8 @@ static void socket_enter_signal(Socket *s, SocketState state, SocketResult f) { if (f != SOCKET_SUCCESS) s->result = f; - if (s->exec_context.kill_mode != KILL_NONE) { - int sig = (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_FINAL_SIGTERM) ? s->exec_context.kill_signal : SIGKILL; + if (s->kill_context.kill_mode != KILL_NONE) { + int sig = (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_FINAL_SIGTERM) ? s->kill_context.kill_signal : SIGKILL; if (s->control_pid > 0) { if (kill_and_sigcont(s->control_pid, sig) < 0 && errno != ESRCH) @@ -1237,7 +1239,7 @@ static void socket_enter_signal(Socket *s, SocketState state, SocketResult f) { wait_for_exit = true; } - if (s->exec_context.kill_mode == KILL_CONTROL_GROUP) { + if (s->kill_context.kill_mode == KILL_CONTROL_GROUP) { if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func))) { r = -ENOMEM; @@ -1983,7 +1985,7 @@ static void socket_timer_event(Unit *u, uint64_t elapsed, Watch *w) { break; case SOCKET_STOP_PRE_SIGTERM: - if (s->exec_context.send_sigkill) { + if (s->kill_context.send_sigkill) { log_warning("%s stopping timed out. Killing.", u->id); socket_enter_signal(s, SOCKET_STOP_PRE_SIGKILL, SOCKET_FAILURE_TIMEOUT); } else { @@ -2003,7 +2005,7 @@ static void socket_timer_event(Unit *u, uint64_t elapsed, Watch *w) { break; case SOCKET_FINAL_SIGTERM: - if (s->exec_context.send_sigkill) { + if (s->kill_context.send_sigkill) { log_warning("%s stopping timed out (2). Killing.", u->id); socket_enter_signal(s, SOCKET_FINAL_SIGKILL, SOCKET_FAILURE_TIMEOUT); } else { diff --git a/src/core/socket.h b/src/core/socket.h index 508f00eb3..a06b3eae9 100644 --- a/src/core/socket.h +++ b/src/core/socket.h @@ -101,6 +101,7 @@ struct Socket { ExecCommand* exec_command[_SOCKET_EXEC_COMMAND_MAX]; ExecContext exec_context; + KillContext kill_context; /* For Accept=no sockets refers to the one service we'll activate. For Accept=yes sockets is either NULL, or filled diff --git a/src/core/swap.c b/src/core/swap.c index ed61ba3c8..03993b1e6 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -86,6 +86,7 @@ static void swap_init(Unit *u) { exec_context_init(&s->exec_context); s->exec_context.std_output = u->manager->default_std_output; s->exec_context.std_error = u->manager->default_std_error; + kill_context_init(&s->kill_context); s->parameters_proc_swaps.priority = s->parameters_fragment.priority = -1; @@ -235,7 +236,7 @@ static int swap_verify(Swap *s) { return -EINVAL; } - if (s->exec_context.pam_name && s->exec_context.kill_mode != KILL_CONTROL_GROUP) { + if (s->exec_context.pam_name && s->kill_context.kill_mode != KILL_CONTROL_GROUP) { log_error("%s has PAM enabled. Kill mode must be set to 'control-group'. Refusing.", UNIT(s)->id); return -EINVAL; } @@ -569,6 +570,7 @@ static void swap_dump(Unit *u, FILE *f, const char *prefix) { prefix, (unsigned long) s->control_pid); exec_context_dump(&s->exec_context, f, prefix); + kill_context_dump(&s->kill_context, f, prefix); } static int swap_spawn(Swap *s, ExecCommand *c, pid_t *_pid) { @@ -641,9 +643,9 @@ static void swap_enter_signal(Swap *s, SwapState state, SwapResult f) { if (f != SWAP_SUCCESS) s->result = f; - if (s->exec_context.kill_mode != KILL_NONE) { + if (s->kill_context.kill_mode != KILL_NONE) { int sig = (state == SWAP_ACTIVATING_SIGTERM || - state == SWAP_DEACTIVATING_SIGTERM) ? s->exec_context.kill_signal : SIGKILL; + state == SWAP_DEACTIVATING_SIGTERM) ? s->kill_context.kill_signal : SIGKILL; if (s->control_pid > 0) { if (kill_and_sigcont(s->control_pid, sig) < 0 && errno != ESRCH) @@ -653,7 +655,7 @@ static void swap_enter_signal(Swap *s, SwapState state, SwapResult f) { wait_for_exit = true; } - if (s->exec_context.kill_mode == KILL_CONTROL_GROUP) { + if (s->kill_context.kill_mode == KILL_CONTROL_GROUP) { if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func))) { r = -ENOMEM; @@ -993,7 +995,7 @@ static void swap_timer_event(Unit *u, uint64_t elapsed, Watch *w) { break; case SWAP_ACTIVATING_SIGTERM: - if (s->exec_context.send_sigkill) { + if (s->kill_context.send_sigkill) { log_warning("%s activation timed out. Killing.", u->id); swap_enter_signal(s, SWAP_ACTIVATING_SIGKILL, SWAP_FAILURE_TIMEOUT); } else { @@ -1003,7 +1005,7 @@ static void swap_timer_event(Unit *u, uint64_t elapsed, Watch *w) { break; case SWAP_DEACTIVATING_SIGTERM: - if (s->exec_context.send_sigkill) { + if (s->kill_context.send_sigkill) { log_warning("%s deactivation timed out. Killing.", u->id); swap_enter_signal(s, SWAP_DEACTIVATING_SIGKILL, SWAP_FAILURE_TIMEOUT); } else { diff --git a/src/core/swap.h b/src/core/swap.h index d8888e176..35d47fd46 100644 --- a/src/core/swap.h +++ b/src/core/swap.h @@ -87,6 +87,7 @@ struct Swap { ExecCommand exec_command[_SWAP_EXEC_COMMAND_MAX]; ExecContext exec_context; + KillContext kill_context; SwapState state, deserialized_state;