diff options
author | Yegor Alexeyev <yegor.alexeyev@gmail.com> | 2021-07-25 05:20:27 +0300 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-08-10 17:08:00 +0200 |
commit | 836fb00f2190811c2bf804860f5afe1160d10eac (patch) | |
tree | 96814ed9e07684476e5f6f8c04a3bc370e9c5dcb /src | |
parent | b553abd8aed0f6fbff9973882fb08c3aec1d9400 (diff) | |
download | systemd-836fb00f2190811c2bf804860f5afe1160d10eac.tar.gz |
units: added factory-reset.target
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/special.h | 1 | ||||
-rw-r--r-- | src/login/logind-action.c | 3 | ||||
-rw-r--r-- | src/login/logind-action.h | 1 | ||||
-rw-r--r-- | src/login/logind-dbus.c | 74 | ||||
-rw-r--r-- | src/systemd/sd-messages.h | 3 |
5 files changed, 54 insertions, 28 deletions
diff --git a/src/basic/special.h b/src/basic/special.h index 78f22f1ac9..5d1111fd71 100644 --- a/src/basic/special.h +++ b/src/basic/special.h @@ -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" diff --git a/src/login/logind-action.c b/src/login/logind-action.c index 8ed066c25e..e172910948 100644 --- a/src/login/logind-action.c +++ b/src/login/logind-action.c @@ -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", }; diff --git a/src/login/logind-action.h b/src/login/logind-action.h index 0baad37a84..ec2fece2b7 100644 --- a/src/login/logind-action.h +++ b/src/login/logind-action.h @@ -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; diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index ccda0bdec4..6e9dde1c15 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -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) { diff --git a/src/systemd/sd-messages.h b/src/systemd/sd-messages.h index eb285efe94..b9445cf0a9 100644 --- a/src/systemd/sd-messages.h +++ b/src/systemd/sd-messages.h @@ -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. */ |