Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logind: log wall messages to the journal #23870

Merged
merged 1 commit into from Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/login/logind-dbus.c
Expand Up @@ -2347,7 +2347,6 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd

if (m->enable_wall_messages) {
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
_cleanup_free_ char *username = NULL;
const char *tty = NULL;
uid_t uid = 0;

Expand All @@ -2357,7 +2356,14 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd
(void) sd_bus_creds_get_tty(creds, &tty);
}

username = uid_to_name(uid);
_cleanup_free_ char *username = uid_to_name(uid);

log_struct(LOG_INFO,
LOG_MESSAGE("System shutdown has been cancelled"),
"ACTION=%s", handle_action_to_string(a->handle),
"MESSAGE_ID=" SD_MESSAGE_LOGIND_SHUTDOWN_CANCELED_STR,
username ? "OPERATOR=%s" : NULL, username);

utmp_wall("System shutdown has been cancelled",
username, tty, logind_wall_tty_filter, m);
}
Expand Down
31 changes: 19 additions & 12 deletions src/login/logind-utmp.c
Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions src/systemd/sd-messages.h
Expand Up @@ -203,6 +203,14 @@ _SD_BEGIN_DECLARATIONS;
#define SD_MESSAGE_TIME_SYNC SD_ID128_MAKE(7c,8a,41,f3,7b,76,49,41,a0,e1,78,0b,1b,e2,f0,37)
#define SD_MESSAGE_TIME_SYNC_STR SD_ID128_MAKE_STR(7c,8a,41,f3,7b,76,49,41,a0,e1,78,0b,1b,e2,f0,37)

#define SD_MESSAGE_LOGIND_SHUTDOWN SD_ID128_MAKE(9e,70,66,27,9d,c8,40,3d,a7,9c,e4,b1,a6,90,64,b2)
bluca marked this conversation as resolved.
Show resolved Hide resolved
#define SD_MESSAGE_LOGIND_SHUTDOWN_STR SD_ID128_MAKE_STR(9e,70,66,27,9d,c8,40,3d,a7,9c,e4,b1,a6,90,64,b2)

#define SD_MESSAGE_LOGIND_SHUTDOWN_CANCELED \
SD_ID128_MAKE(24,9f,6f,b9,e6,e2,42,8c,96,f3,f0,87,56,81,ff,a3)
#define SD_MESSAGE_LOGIND_SHUTDOWN_CANCELED_STR \
SD_ID128_MAKE_STR(24,9f,6f,b9,e6,e2,42,8c,96,f3,f0,87,56,81,ff,a3)

_SD_END_DECLARATIONS;

#endif