mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-02-21 13:58:00 +03:00
units: added factory-reset.target
This commit is contained in:
parent
b553abd8ae
commit
836fb00f21
@ -188,6 +188,15 @@ Support: %SUPPORT_URL%
|
||||
System shutdown has been initiated. The shutdown has now begun and
|
||||
all system services are terminated and all file systems unmounted.
|
||||
|
||||
-- c14aaf76ec284a5fa1f105f88dfb061c
|
||||
Subject: System factory reset initiated
|
||||
Defined-By: systemd
|
||||
Support: %SUPPORT_URL%
|
||||
|
||||
System factory reset has been initiated. The precise operation this
|
||||
executes is implementation-defined, but typically has the effect of
|
||||
reverting the system's state and configuration to vendor defaults.
|
||||
|
||||
-- 7d4958e842da4a758f6c1cdc7b36dcc5
|
||||
Subject: A start job for unit @UNIT@ has begun execution
|
||||
Defined-By: systemd
|
||||
|
@ -216,8 +216,9 @@
|
||||
<literal>suspend</literal>,
|
||||
<literal>hibernate</literal>,
|
||||
<literal>hybrid-sleep</literal>,
|
||||
<literal>suspend-then-hibernate</literal>, and
|
||||
<literal>lock</literal>.
|
||||
<literal>suspend-then-hibernate</literal>,
|
||||
<literal>lock</literal>, and
|
||||
<literal>factory-reset</literal>.
|
||||
If <literal>ignore</literal>, logind will never handle these
|
||||
keys. If <literal>lock</literal>, all running sessions will be
|
||||
screen-locked; otherwise, the specified action will be taken
|
||||
|
@ -33,6 +33,7 @@
|
||||
<filename>default.target</filename>,
|
||||
<filename>emergency.target</filename>,
|
||||
<filename>exit.target</filename>,
|
||||
<filename>factory-reset.target</filename>,
|
||||
<filename>final.target</filename>,
|
||||
<filename>first-boot-complete.target</filename>,
|
||||
<filename>getty.target</filename>,
|
||||
@ -279,6 +280,12 @@
|
||||
shutdown when the service manager starts to exit.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><filename>factory-reset.target</filename></term>
|
||||
<listitem>
|
||||
<para>A special target to trigger a factory reset.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><filename>final.target</filename></term>
|
||||
<listitem>
|
||||
|
@ -20,6 +20,7 @@
|
||||
#define SPECIAL_HIBERNATE_TARGET "hibernate.target"
|
||||
#define SPECIAL_HYBRID_SLEEP_TARGET "hybrid-sleep.target"
|
||||
#define SPECIAL_SUSPEND_THEN_HIBERNATE_TARGET "suspend-then-hibernate.target"
|
||||
#define SPECIAL_FACTORY_RESET_TARGET "factory-reset.target"
|
||||
|
||||
/* Special boot targets */
|
||||
#define SPECIAL_RESCUE_TARGET "rescue.target"
|
||||
|
@ -27,6 +27,7 @@ const char* manager_target_for_action(HandleAction handle) {
|
||||
[HANDLE_HIBERNATE] = SPECIAL_HIBERNATE_TARGET,
|
||||
[HANDLE_HYBRID_SLEEP] = SPECIAL_HYBRID_SLEEP_TARGET,
|
||||
[HANDLE_SUSPEND_THEN_HIBERNATE] = SPECIAL_SUSPEND_THEN_HIBERNATE_TARGET,
|
||||
[HANDLE_FACTORY_RESET] = SPECIAL_FACTORY_RESET_TARGET,
|
||||
};
|
||||
|
||||
assert(handle >= 0);
|
||||
@ -51,6 +52,7 @@ int manager_handle_action(
|
||||
[HANDLE_HIBERNATE] = "Hibernating...",
|
||||
[HANDLE_HYBRID_SLEEP] = "Hibernating and suspending...",
|
||||
[HANDLE_SUSPEND_THEN_HIBERNATE] = "Suspending, then hibernating...",
|
||||
[HANDLE_FACTORY_RESET] = "Performing factory reset...",
|
||||
};
|
||||
|
||||
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
@ -179,6 +181,7 @@ static const char* const handle_action_table[_HANDLE_ACTION_MAX] = {
|
||||
[HANDLE_HIBERNATE] = "hibernate",
|
||||
[HANDLE_HYBRID_SLEEP] = "hybrid-sleep",
|
||||
[HANDLE_SUSPEND_THEN_HIBERNATE] = "suspend-then-hibernate",
|
||||
[HANDLE_FACTORY_RESET] = "factory-reset",
|
||||
[HANDLE_LOCK] = "lock",
|
||||
};
|
||||
|
||||
|
@ -14,6 +14,7 @@ typedef enum HandleAction {
|
||||
HANDLE_HYBRID_SLEEP,
|
||||
HANDLE_SUSPEND_THEN_HIBERNATE,
|
||||
HANDLE_LOCK,
|
||||
HANDLE_FACTORY_RESET,
|
||||
_HANDLE_ACTION_MAX,
|
||||
_HANDLE_ACTION_INVALID = -EINVAL,
|
||||
} HandleAction;
|
||||
|
@ -1491,41 +1491,59 @@ static int have_multiple_sessions(
|
||||
return false;
|
||||
}
|
||||
|
||||
static int bus_manager_log_shutdown(
|
||||
Manager *m,
|
||||
const char *unit_name) {
|
||||
|
||||
const char *p, *q;
|
||||
|
||||
_printf_(2, 0)
|
||||
static int log_with_wall_message(Manager *m, const char *d, const char *p, const char *q) {
|
||||
assert(m);
|
||||
assert(unit_name);
|
||||
|
||||
if (streq(unit_name, SPECIAL_POWEROFF_TARGET)) {
|
||||
p = "MESSAGE=System is powering down";
|
||||
q = "SHUTDOWN=power-off";
|
||||
} else if (streq(unit_name, SPECIAL_REBOOT_TARGET)) {
|
||||
p = "MESSAGE=System is rebooting";
|
||||
q = "SHUTDOWN=reboot";
|
||||
} else if (streq(unit_name, SPECIAL_HALT_TARGET)) {
|
||||
p = "MESSAGE=System is halting";
|
||||
q = "SHUTDOWN=halt";
|
||||
} else if (streq(unit_name, SPECIAL_KEXEC_TARGET)) {
|
||||
p = "MESSAGE=System is rebooting with kexec";
|
||||
q = "SHUTDOWN=kexec";
|
||||
} else {
|
||||
p = "MESSAGE=System is shutting down";
|
||||
q = NULL;
|
||||
}
|
||||
|
||||
if (isempty(m->wall_message))
|
||||
p = strjoina(p, ".");
|
||||
else
|
||||
p = strjoina(p, " (", m->wall_message, ").");
|
||||
|
||||
return log_struct(LOG_NOTICE,
|
||||
"MESSAGE_ID=" SD_MESSAGE_SHUTDOWN_STR,
|
||||
p,
|
||||
q);
|
||||
return log_struct(LOG_NOTICE, d, p, q);
|
||||
}
|
||||
|
||||
static int bus_manager_log_shutdown(
|
||||
Manager *m,
|
||||
const char *unit_name) {
|
||||
|
||||
assert(m);
|
||||
assert(unit_name);
|
||||
|
||||
if (streq(unit_name, SPECIAL_POWEROFF_TARGET))
|
||||
return log_with_wall_message(m,
|
||||
"MESSAGE_ID=" SD_MESSAGE_SHUTDOWN_STR,
|
||||
"MESSAGE=System is powering down",
|
||||
"SHUTDOWN=power-off");
|
||||
|
||||
if (streq(unit_name, SPECIAL_REBOOT_TARGET))
|
||||
return log_with_wall_message(m,
|
||||
"MESSAGE_ID=" SD_MESSAGE_SHUTDOWN_STR,
|
||||
"MESSAGE=System is rebooting",
|
||||
"SHUTDOWN=reboot");
|
||||
|
||||
if (streq(unit_name, SPECIAL_HALT_TARGET))
|
||||
return log_with_wall_message(m,
|
||||
"MESSAGE_ID=" SD_MESSAGE_SHUTDOWN_STR,
|
||||
"MESSAGE=System is halting",
|
||||
"SHUTDOWN=halt");
|
||||
|
||||
if (streq(unit_name, SPECIAL_KEXEC_TARGET))
|
||||
return log_with_wall_message(m,
|
||||
"MESSAGE_ID=" SD_MESSAGE_SHUTDOWN_STR,
|
||||
"MESSAGE=System is rebooting with kexec",
|
||||
"SHUTDOWN=kexec");
|
||||
|
||||
if (streq(unit_name, SPECIAL_FACTORY_RESET_TARGET))
|
||||
return log_with_wall_message(m,
|
||||
"MESSAGE_ID=" SD_MESSAGE_FACTORY_RESET_STR,
|
||||
"MESSAGE=System is performing factory reset",
|
||||
NULL);
|
||||
|
||||
return log_with_wall_message(m,
|
||||
"MESSAGE_ID=" SD_MESSAGE_SHUTDOWN_STR,
|
||||
"MESSAGE=System is shutting down",
|
||||
NULL);
|
||||
}
|
||||
|
||||
static int lid_switch_ignore_handler(sd_event_source *e, uint64_t usec, void *userdata) {
|
||||
|
@ -81,6 +81,9 @@ _SD_BEGIN_DECLARATIONS;
|
||||
#define SD_MESSAGE_SHUTDOWN SD_ID128_MAKE(98,26,88,66,d1,d5,4a,49,9c,4e,98,92,1d,93,bc,40)
|
||||
#define SD_MESSAGE_SHUTDOWN_STR SD_ID128_MAKE_STR(98,26,88,66,d1,d5,4a,49,9c,4e,98,92,1d,93,bc,40)
|
||||
|
||||
#define SD_MESSAGE_FACTORY_RESET SD_ID128_MAKE(c1,4a,af,76,ec,28,4a,5f,a1,f1,05,f8,8d,fb,06,1c)
|
||||
#define SD_MESSAGE_FACTORY_RESET_STR SD_ID128_MAKE_STR(c1,4a,af,76,ec,28,4a,5f,a1,f1,05,f8,8d,fb,06,1c)
|
||||
|
||||
/* The messages below are actually about jobs, not really about units, the macros are misleadingly named. Moreover
|
||||
* SD_MESSAGE_UNIT_FAILED is not actually about a failing unit but about a failed start job. A job either finishes with
|
||||
* SD_MESSAGE_UNIT_STARTED or with SD_MESSAGE_UNIT_FAILED hence. */
|
||||
|
12
units/factory-reset.target
Normal file
12
units/factory-reset.target
Normal file
@ -0,0 +1,12 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
#
|
||||
# This file is part of systemd.
|
||||
#
|
||||
# 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.
|
||||
|
||||
[Unit]
|
||||
Description=Target that triggers factory reset. Does nothing by default.
|
||||
Documentation=man:systemd.special(7)
|
@ -19,6 +19,7 @@ units = [
|
||||
'sysinit.target.wants/'],
|
||||
['emergency.target', ''],
|
||||
['exit.target', ''],
|
||||
['factory-reset.target', ''],
|
||||
['final.target', ''],
|
||||
['first-boot-complete.target', ''],
|
||||
['getty.target', '',
|
||||
|
Loading…
x
Reference in New Issue
Block a user