Merge pull request #6715 from sourcejedi/kbrequest-jobmode2

Fix #6484 "4 or 5 out of 7 targets triggered by SIGRTMIN+X use the wrong job mode"
This commit is contained in:
Lennart Poettering
2017-09-01 09:38:04 +02:00
committed by GitHub
5 changed files with 43 additions and 46 deletions
+2 -1
View File
@@ -295,7 +295,8 @@
transactions from replacing these jobs (or even being enqueued
while the irreversible jobs are still pending). Irreversible
jobs can still be cancelled using the <command>cancel</command>
command.</para>
command. This job mode should be used on any transaction which
pulls in <filename>shutdown.target</filename>.</para>
<para><literal>isolate</literal> is only valid for start
operations and causes all other units to be stopped when the
+1 -2
View File
@@ -238,8 +238,7 @@
<filename>poweroff.target</filename> on non-container
systems, and also works in containers.</para>
<para>systemd will start this unit when it receives a
request to shut down over D-Bus or a
<para>systemd will start this unit when it receives the
<constant>SIGTERM</constant> or <constant>SIGINT</constant>
signal when running as user service daemon.</para>
+22 -17
View File
@@ -561,7 +561,8 @@
<para>systemd user managers will start the
<filename>exit.target</filename> unit when this signal is
received. This is mostly equivalent to <command>systemctl
--user start exit.target</command>.</para></listitem>
--user start exit.target
--job-mode=replace-irreversible</command>.</para></listitem>
</varlistentry>
<varlistentry>
@@ -570,13 +571,13 @@
<listitem><para>Upon receiving this signal the systemd system
manager will start the
<filename>ctrl-alt-del.target</filename> unit. This is mostly
equivalent to <command>systemctl start
ctl-alt-del.target</command>. If this signal is received more
than 7 times per 2s, an immediate reboot is triggered.
Note that pressing Ctrl-Alt-Del on the console will trigger
this signal. Hence, if a reboot is hanging, pressing
Ctrl-Alt-Del more than 7 times in 2s is a relatively safe way
to trigger an immediate reboot.</para>
equivalent to <command>systemctl start ctl-alt-del.target
--job-mode=replace-irreversible</command>. If this signal is
received more than 7 times per 2s, an immediate reboot is
triggered. Note that pressing Ctrl-Alt-Del on the console
will trigger this signal. Hence, if a reboot is hanging,
pressing Ctrl-Alt-Del more than 7 times in 2s is a relatively
safe way to trigger an immediate reboot.</para>
<para>systemd user managers treat this signal the same way as
<constant>SIGTERM</constant>.</para></listitem>
@@ -634,7 +635,7 @@
<listitem><para>Enters default mode, starts the
<filename>default.target</filename> unit. This is mostly
equivalent to <command>systemctl start
equivalent to <command>systemctl isolate
default.target</command>.</para></listitem>
</varlistentry>
@@ -661,8 +662,9 @@
<listitem><para>Halts the machine, starts the
<filename>halt.target</filename> unit. This is mostly
equivalent to <command>systemctl start
halt.target</command>.</para></listitem>
equivalent to <command>systemctl start halt.target
--job-mode=replace-irreversible</command>.</para>
</listitem>
</varlistentry>
<varlistentry>
@@ -670,8 +672,9 @@
<listitem><para>Powers off the machine, starts the
<filename>poweroff.target</filename> unit. This is mostly
equivalent to <command>systemctl start
poweroff.target</command>.</para></listitem>
equivalent to <command>systemctl start poweroff.target
--job-mode=replace-irreversible</command>.</para>
</listitem>
</varlistentry>
<varlistentry>
@@ -679,8 +682,9 @@
<listitem><para>Reboots the machine, starts the
<filename>reboot.target</filename> unit. This is mostly
equivalent to <command>systemctl start
reboot.target</command>.</para></listitem>
equivalent to <command>systemctl start reboot.target
--job-mode=replace-irreversible</command>.</para>
</listitem>
</varlistentry>
<varlistentry>
@@ -688,8 +692,9 @@
<listitem><para>Reboots the machine via kexec, starts the
<filename>kexec.target</filename> unit. This is mostly
equivalent to <command>systemctl start
kexec.target</command>.</para></listitem>
equivalent to <command>systemctl start kexec.target
--job-mode=replace-irreversible</command>.</para>
</listitem>
</varlistentry>
<varlistentry>
+18 -23
View File
@@ -2012,7 +2012,7 @@ static int manager_dispatch_sigchld(Manager *m) {
return 0;
}
static int manager_start_target(Manager *m, const char *name, JobMode mode) {
static void manager_start_target(Manager *m, const char *name, JobMode mode) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
int r;
@@ -2021,8 +2021,6 @@ static int manager_start_target(Manager *m, const char *name, JobMode mode) {
r = manager_add_job_by_name(m, JOB_START, name, mode, &error, NULL);
if (r < 0)
log_error("Failed to enqueue %s job: %s", name, bus_error_message(&error, r));
return r;
}
static void manager_handle_ctrl_alt_del(Manager *m) {
@@ -2092,17 +2090,11 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t
/* Fall through */
case SIGINT:
if (MANAGER_IS_SYSTEM(m)) {
if (MANAGER_IS_SYSTEM(m))
manager_handle_ctrl_alt_del(m);
break;
}
/* Run the exit target if there is one, if not, just exit. */
if (manager_start_target(m, SPECIAL_EXIT_TARGET, JOB_REPLACE) < 0) {
m->exit_code = MANAGER_EXIT;
return 0;
}
else
manager_start_target(m, SPECIAL_EXIT_TARGET,
JOB_REPLACE_IRREVERSIBLY);
break;
case SIGWINCH:
@@ -2170,14 +2162,17 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t
default: {
/* Starting SIGRTMIN+0 */
static const char * const target_table[] = {
[0] = SPECIAL_DEFAULT_TARGET,
[1] = SPECIAL_RESCUE_TARGET,
[2] = SPECIAL_EMERGENCY_TARGET,
[3] = SPECIAL_HALT_TARGET,
[4] = SPECIAL_POWEROFF_TARGET,
[5] = SPECIAL_REBOOT_TARGET,
[6] = SPECIAL_KEXEC_TARGET
static const struct {
const char *target;
JobMode mode;
} target_table[] = {
[0] = { SPECIAL_DEFAULT_TARGET, JOB_ISOLATE },
[1] = { SPECIAL_RESCUE_TARGET, JOB_ISOLATE },
[2] = { SPECIAL_EMERGENCY_TARGET, JOB_ISOLATE },
[3] = { SPECIAL_HALT_TARGET, JOB_REPLACE_IRREVERSIBLY },
[4] = { SPECIAL_POWEROFF_TARGET, JOB_REPLACE_IRREVERSIBLY },
[5] = { SPECIAL_REBOOT_TARGET, JOB_REPLACE_IRREVERSIBLY },
[6] = { SPECIAL_KEXEC_TARGET, JOB_REPLACE_IRREVERSIBLY }
};
/* Starting SIGRTMIN+13, so that target halt and system halt are 10 apart */
@@ -2191,8 +2186,8 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t
if ((int) sfsi.ssi_signo >= SIGRTMIN+0 &&
(int) sfsi.ssi_signo < SIGRTMIN+(int) ELEMENTSOF(target_table)) {
int idx = (int) sfsi.ssi_signo - SIGRTMIN;
manager_start_target(m, target_table[idx],
(idx == 1 || idx == 2) ? JOB_ISOLATE : JOB_REPLACE);
manager_start_target(m, target_table[idx].target,
target_table[idx].mode);
break;
}
-3
View File
@@ -11,6 +11,3 @@ Documentation=man:systemd.special(7)
Requires=sysinit.target rescue.service
After=sysinit.target rescue.service
AllowIsolate=yes
[Install]
Alias=kbrequest.target