From: Christian Göttsche Date: Fri, 27 May 2022 11:47:23 +0000 (+0200) Subject: login: do not issue wall messages on local terminals for suspend and hibernate X-Git-Tag: v252-rc1~887^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F23574%2Fhead;p=thirdparty%2Fsystemd.git login: do not issue wall messages on local terminals for suspend and hibernate Fixes: #23520 [zjs: I added the comment and tweaked the patch a bit. The call to reset_scheduled_shutdown() is moved down a bit to allow the callback to have access to information about the operation being cancelled. This all happens within the same function, so there should be no observable change in behaviour.] --- diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index f7cff580051..c40d8defaf1 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -2342,8 +2342,6 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd if (r == 0) return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ - reset_scheduled_shutdown(m); - if (m->enable_wall_messages) { _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; _cleanup_free_ char *username = NULL; @@ -2361,6 +2359,8 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd username, tty, logind_wall_tty_filter, m); } + reset_scheduled_shutdown(m); + return sd_bus_reply_method_return(message, "b", true); } diff --git a/src/login/logind-utmp.c b/src/login/logind-utmp.c index 138c01e9b27..7d761a0d674 100644 --- a/src/login/logind-utmp.c +++ b/src/login/logind-utmp.c @@ -45,12 +45,22 @@ _const_ static usec_t when_wall(usec_t n, usec_t elapse) { bool logind_wall_tty_filter(const char *tty, bool is_local, void *userdata) { Manager *m = ASSERT_PTR(userdata); + assert(m->scheduled_shutdown_action); + const char *p = path_startswith(tty, "/dev/"); if (!p) return true; - /* Do not write to local pseudo-terminals */ - if (startswith(p, "pts/") && is_local) + /* Do not send information about events which do not destroy local sessions to local terminals. We + * can assume that if the system enters sleep or hibernation, this will be visible in an obvious way + * for any local user. And once the systems exits sleep or hibernation, the notication would be just + * noise, in particular for auto-suspend. */ + if (is_local && + IN_SET(m->scheduled_shutdown_action->handle, + HANDLE_SUSPEND, + HANDLE_HIBERNATE, + HANDLE_HYBRID_SLEEP, + HANDLE_SUSPEND_THEN_HIBERNATE)) return false; return !streq_ptr(p, m->scheduled_shutdown_tty);