summaryrefslogtreecommitdiff
path: root/src/login
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-06-01 16:26:29 +0200
committerGitHub <noreply@github.com>2022-06-01 16:26:29 +0200
commit14c811ff4a3025a3ba8b969f7228c05d31eb3796 (patch)
tree7bb36aa66bd88050cbcf5021a5e4303782e16ac9 /src/login
parentd5254fa2f6f6d779ae04ca47a419794b02cb3b2e (diff)
parentb622d2f7898302f83458fa7863c60087c7f8048b (diff)
downloadsystemd-14c811ff4a3025a3ba8b969f7228c05d31eb3796.tar.gz
Merge pull request #23575 from keszybz/logind-wall-message-cleanup
Cleanup wall messages emitted by logind and systemctl
Diffstat (limited to 'src/login')
-rw-r--r--src/login/logind-action.c52
-rw-r--r--src/login/logind-action.h2
-rw-r--r--src/login/logind-dbus.c11
-rw-r--r--src/login/logind-utmp.c33
-rw-r--r--src/login/logind.c2
5 files changed, 57 insertions, 43 deletions
diff --git a/src/login/logind-action.c b/src/login/logind-action.c
index 6a873009bc..c6a36a1556 100644
--- a/src/login/logind-action.c
+++ b/src/login/logind-action.c
@@ -129,15 +129,15 @@ int manager_handle_action(
bool is_edge) {
static const char * const message_table[_HANDLE_ACTION_MAX] = {
- [HANDLE_POWEROFF] = "Powering Off...",
- [HANDLE_REBOOT] = "Rebooting...",
- [HANDLE_HALT] = "Halting...",
- [HANDLE_KEXEC] = "Rebooting via kexec...",
- [HANDLE_SUSPEND] = "Suspending...",
- [HANDLE_HIBERNATE] = "Hibernating...",
- [HANDLE_HYBRID_SLEEP] = "Hibernating and suspending...",
+ [HANDLE_POWEROFF] = "Powering off...",
+ [HANDLE_REBOOT] = "Rebooting...",
+ [HANDLE_HALT] = "Halting...",
+ [HANDLE_KEXEC] = "Rebooting via kexec...",
+ [HANDLE_SUSPEND] = "Suspending...",
+ [HANDLE_HIBERNATE] = "Hibernating...",
+ [HANDLE_HYBRID_SLEEP] = "Hibernating and suspending...",
[HANDLE_SUSPEND_THEN_HIBERNATE] = "Suspending, then hibernating...",
- [HANDLE_FACTORY_RESET] = "Performing factory reset...",
+ [HANDLE_FACTORY_RESET] = "Performing factory reset...",
};
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
@@ -251,18 +251,34 @@ int manager_handle_action(
return 1;
}
+static const char* const handle_action_verb_table[_HANDLE_ACTION_MAX] = {
+ [HANDLE_IGNORE] = "do nothing",
+ [HANDLE_POWEROFF] = "power off",
+ [HANDLE_REBOOT] = "reboot",
+ [HANDLE_HALT] = "halt",
+ [HANDLE_KEXEC] = "kexec",
+ [HANDLE_SUSPEND] = "suspend",
+ [HANDLE_HIBERNATE] = "hibernate",
+ [HANDLE_HYBRID_SLEEP] = "enter hybrid sleep",
+ [HANDLE_SUSPEND_THEN_HIBERNATE] = "suspend and later hibernate",
+ [HANDLE_FACTORY_RESET] = "perform a factory reset",
+ [HANDLE_LOCK] = "be locked",
+};
+
+DEFINE_STRING_TABLE_LOOKUP_TO_STRING(handle_action_verb, HandleAction);
+
static const char* const handle_action_table[_HANDLE_ACTION_MAX] = {
- [HANDLE_IGNORE] = "ignore",
- [HANDLE_POWEROFF] = "poweroff",
- [HANDLE_REBOOT] = "reboot",
- [HANDLE_HALT] = "halt",
- [HANDLE_KEXEC] = "kexec",
- [HANDLE_SUSPEND] = "suspend",
- [HANDLE_HIBERNATE] = "hibernate",
- [HANDLE_HYBRID_SLEEP] = "hybrid-sleep",
+ [HANDLE_IGNORE] = "ignore",
+ [HANDLE_POWEROFF] = "poweroff",
+ [HANDLE_REBOOT] = "reboot",
+ [HANDLE_HALT] = "halt",
+ [HANDLE_KEXEC] = "kexec",
+ [HANDLE_SUSPEND] = "suspend",
+ [HANDLE_HIBERNATE] = "hibernate",
+ [HANDLE_HYBRID_SLEEP] = "hybrid-sleep",
[HANDLE_SUSPEND_THEN_HIBERNATE] = "suspend-then-hibernate",
- [HANDLE_FACTORY_RESET] = "factory-reset",
- [HANDLE_LOCK] = "lock",
+ [HANDLE_FACTORY_RESET] = "factory-reset",
+ [HANDLE_LOCK] = "lock",
};
DEFINE_STRING_TABLE_LOOKUP(handle_action, HandleAction);
diff --git a/src/login/logind-action.h b/src/login/logind-action.h
index c891787e6c..9a01af1690 100644
--- a/src/login/logind-action.h
+++ b/src/login/logind-action.h
@@ -49,6 +49,8 @@ int manager_handle_action(
bool ignore_inhibited,
bool is_edge);
+const char* handle_action_verb_to_string(HandleAction h) _const_;
+
const char* handle_action_to_string(HandleAction h) _const_;
HandleAction handle_action_from_string(const char *s) _pure_;
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index c40d8defaf..031b96e9f1 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -1888,9 +1888,11 @@ static int method_do_shutdown_or_sleep(
if (r < 0)
return r;
if ((flags & ~SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_PUBLIC) != 0)
- return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid flags parameter");
+ return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS,
+ "Invalid flags parameter");
if (a->handle != HANDLE_REBOOT && (flags & SD_LOGIND_REBOOT_VIA_KEXEC))
- return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Reboot via kexec is only applicable with reboot operations");
+ return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS,
+ "Reboot via kexec is only applicable with reboot operations");
} else {
/* Old style method: no flags parameter, but interactive bool passed as boolean in
* payload. Let's convert this argument to the new-style flags parameter for our internal
@@ -1919,7 +1921,8 @@ static int method_do_shutdown_or_sleep(
"Not enough swap space for hibernation");
if (r == 0)
return sd_bus_error_setf(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED,
- "Sleep verb \"%s\" not supported", sleep_operation_to_string(a->sleep_operation));
+ "Sleep verb \"%s\" not supported",
+ sleep_operation_to_string(a->sleep_operation));
if (r < 0)
return r;
}
@@ -2355,7 +2358,7 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd
}
username = uid_to_name(uid);
- utmp_wall("The system shutdown has been cancelled",
+ utmp_wall("System shutdown has been cancelled",
username, tty, logind_wall_tty_filter, m);
}
diff --git a/src/login/logind-utmp.c b/src/login/logind-utmp.c
index 7d761a0d67..36a3fcd0e9 100644
--- a/src/login/logind-utmp.c
+++ b/src/login/logind-utmp.c
@@ -21,9 +21,6 @@
#include "utmp-wtmp.h"
_const_ static usec_t when_wall(usec_t n, usec_t elapse) {
-
- usec_t left;
- unsigned i;
static const int wall_timers[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
25, 40, 55, 70, 100, 130, 150, 180,
@@ -33,9 +30,9 @@ _const_ static usec_t when_wall(usec_t n, usec_t elapse) {
if (n >= elapse)
return 0;
- left = elapse - n;
+ usec_t left = elapse - n;
- for (i = 1; i < ELEMENTSOF(wall_timers); i++)
+ for (unsigned i = 1; i < ELEMENTSOF(wall_timers); i++)
if (wall_timers[i] * USEC_PER_MINUTE >= left)
return left - wall_timers[i-1] * USEC_PER_MINUTE;
@@ -67,8 +64,6 @@ bool logind_wall_tty_filter(const char *tty, bool is_local, void *userdata) {
}
static int warn_wall(Manager *m, usec_t n) {
- _cleanup_free_ char *l = NULL, *username = NULL;
- usec_t left;
int r;
assert(m);
@@ -76,13 +71,15 @@ static int warn_wall(Manager *m, usec_t n) {
if (!m->enable_wall_messages || !m->scheduled_shutdown_action)
return 0;
- left = m->scheduled_shutdown_timeout > n;
+ usec_t left = m->scheduled_shutdown_timeout > n;
+
+ _cleanup_free_ char *l = NULL, *username = NULL;
- r = asprintf(&l, "%s%sThe system is going down for %s %s%s!",
+ r = asprintf(&l, "%s%sThe system will %s %s%s!",
strempty(m->wall_message),
isempty(m->wall_message) ? "" : "\n",
- handle_action_to_string(m->scheduled_shutdown_action->handle),
- left ? "at " : "NOW",
+ handle_action_verb_to_string(m->scheduled_shutdown_action->handle),
+ left ? "at " : "now",
left ? FORMAT_TIMESTAMP(m->scheduled_shutdown_timeout) : "");
if (r < 0) {
log_oom();
@@ -100,20 +97,18 @@ static int wall_message_timeout_handler(
uint64_t usec,
void *userdata) {
- Manager *m = userdata;
- usec_t n, next;
+ Manager *m = ASSERT_PTR(userdata);
int r;
- assert(m);
assert(s == m->wall_message_timeout_source);
- n = now(CLOCK_REALTIME);
+ usec_t n = now(CLOCK_REALTIME);
r = warn_wall(m, n);
if (r == 0)
return 0;
- next = when_wall(n, m->scheduled_shutdown_timeout);
+ usec_t next = when_wall(n, m->scheduled_shutdown_timeout);
if (next > 0) {
r = sd_event_source_set_time(s, n + next);
if (r < 0)
@@ -128,14 +123,12 @@ static int wall_message_timeout_handler(
}
int manager_setup_wall_message_timer(Manager *m) {
-
- usec_t n, elapse;
int r;
assert(m);
- n = now(CLOCK_REALTIME);
- elapse = m->scheduled_shutdown_timeout;
+ usec_t n = now(CLOCK_REALTIME);
+ usec_t elapse = m->scheduled_shutdown_timeout;
/* wall message handling */
diff --git a/src/login/logind.c b/src/login/logind.c
index 0483902edd..aa85480548 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -972,7 +972,7 @@ static int manager_dispatch_idle_action(sd_event_source *s, uint64_t t, void *us
if (n >= since.monotonic + m->idle_action_usec &&
(m->idle_action_not_before_usec <= 0 || n >= m->idle_action_not_before_usec + m->idle_action_usec)) {
- log_info("System idle. Doing %s operation.", handle_action_to_string(m->idle_action));
+ log_info("System idle. Will %s now.", handle_action_verb_to_string(m->idle_action));
manager_handle_action(m, 0, m->idle_action, false, false);
m->idle_action_not_before_usec = n;