]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
login: do not issue wall messages on local terminals for suspend and hibernate 23574/head
authorChristian Göttsche <cgzones@googlemail.com>
Fri, 27 May 2022 11:47:23 +0000 (13:47 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 1 Jun 2022 07:30:07 +0000 (09:30 +0200)
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.]

src/login/logind-dbus.c
src/login/logind-utmp.c

index f7cff580051493bd38898dd5b2c684bd7ad3a595..c40d8defaf1f8369198adbf45a91cc10a7643574 100644 (file)
@@ -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);
 }
 
index 138c01e9b27ebc7dea3bf8660315a71a0d4471aa..7d761a0d67488c09106e5a0d53fe8c4772b1f257 100644 (file)
@@ -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);