diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-06-30 12:13:49 +0200 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2022-06-30 19:28:41 +0100 |
commit | 907506695549c689710cd267583f6fd439711dcf (patch) | |
tree | faaf1ba736fdd578d8e76d404ac13b026e223f08 /src/login/logind-utmp.c | |
parent | f63d1b0efa64fe716c2855a0410ac47ad67f7dec (diff) | |
download | systemd-907506695549c689710cd267583f6fd439711dcf.tar.gz |
logind: log wall messages to the journal
Currently kde installs a fake utmp session to listen for this. This provides an
alternative mechanism as discussed in #23574.
Example with 'shutdown 6 -r' and shutdown -c':
PRIORITY=6
SYSLOG_FACILITY=4
SYSLOG_IDENTIFIER=systemd-logind
...
CODE_FILE=src/login/logind-utmp.c
CODE_LINE=90
CODE_FUNC=warn_wall
MESSAGE_ID=9e7066279dc8403da79ce4b1a69064b2
OPERATOR=root
MESSAGE=The system will reboot at Thu 2022-06-30 12:16:43 CEST!
ACTION=reboot
PRIORITY=5
SYSLOG_FACILITY=4
SYSLOG_IDENTIFIER=systemd-logind
...
OPERATOR=root
CODE_FILE=src/login/logind-dbus.c
CODE_LINE=2407
CODE_FUNC=method_cancel_scheduled_shutdown
MESSAGE=System shutdown has been cancelled
MESSAGE_ID=249f6fb9e6e2428c96f3f0875681ffa3
ACTION=reboot
Diffstat (limited to 'src/login/logind-utmp.c')
-rw-r--r-- | src/login/logind-utmp.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/login/logind-utmp.c b/src/login/logind-utmp.c index ccf959cd73..06b1bcf9b4 100644 --- a/src/login/logind-utmp.c +++ b/src/login/logind-utmp.c @@ -64,30 +64,37 @@ bool logind_wall_tty_filter(const char *tty, bool is_local, void *userdata) { } static int warn_wall(Manager *m, usec_t n) { - int r; - assert(m); - if (!m->enable_wall_messages || !m->scheduled_shutdown_action) + if (!m->scheduled_shutdown_action) return 0; - usec_t left = m->scheduled_shutdown_timeout > n; + bool left = m->scheduled_shutdown_timeout > n; - _cleanup_free_ char *l = NULL, *username = NULL; - - r = asprintf(&l, "%s%sThe system will %s %s%s!", + _cleanup_free_ char *l = NULL; + if (asprintf(&l, "%s%sThe system will %s %s%s!", strempty(m->wall_message), isempty(m->wall_message) ? "" : "\n", handle_action_verb_to_string(m->scheduled_shutdown_action->handle), left ? "at " : "now", - left ? FORMAT_TIMESTAMP(m->scheduled_shutdown_timeout) : ""); - if (r < 0) { + left ? FORMAT_TIMESTAMP(m->scheduled_shutdown_timeout) : "") < 0) { + log_oom(); - return 0; + return 1; /* We're out-of-memory for now, but let's try to print the message later */ } - username = uid_to_name(m->scheduled_shutdown_uid); - utmp_wall(l, username, m->scheduled_shutdown_tty, logind_wall_tty_filter, m); + _cleanup_free_ char *username = uid_to_name(m->scheduled_shutdown_uid); + + int level = left ? LOG_INFO : LOG_NOTICE; + + log_struct(level, + LOG_MESSAGE("%s", l), + "ACTION=%s", handle_action_to_string(m->scheduled_shutdown_action->handle), + "MESSAGE_ID=" SD_MESSAGE_LOGIND_SHUTDOWN_STR, + username ? "OPERATOR=%s" : NULL, username); + + if (m->enable_wall_messages) + utmp_wall(l, username, m->scheduled_shutdown_tty, logind_wall_tty_filter, m); return 1; } |