chiark / gitweb /
tree-wide: drop copyright headers from frequent contributors
[elogind.git] / src / login / logind-utmp.c
index 8c2bfb07a19cbfa7405b5b8744310f2a2af4006a..f18147688a2852e7594a71fdb0819c00728db9a7 100644 (file)
@@ -1,23 +1,4 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
-  This file is part of systemd.
-
-  Copyright 2015 Daniel Mack
-
-  systemd is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or
-  (at your option) any later version.
-
-  systemd is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
+/* SPDX-License-Identifier: LGPL-2.1+ */
 
 #include <errno.h>
 #include <pwd.h>
@@ -31,8 +12,9 @@
 #include "bus-common-errors.h"
 #include "bus-error.h"
 #include "bus-util.h"
-#include "formats-util.h"
+#include "format-util.h"
 #include "logind.h"
+#include "path-util.h"
 //#include "special.h"
 #include "strv.h"
 #include "unit-name.h"
@@ -62,15 +44,19 @@ _const_ static usec_t when_wall(usec_t n, usec_t elapse) {
 }
 
 bool logind_wall_tty_filter(const char *tty, void *userdata) {
-
         Manager *m = userdata;
+        const char *p;
 
         assert(m);
 
-        if (!startswith(tty, "/dev/"))
+        if (!m->scheduled_shutdown_tty)
+                return true;
+
+        p = path_startswith(tty, "/dev/");
+        if (!p)
                 return true;
 
-        return !streq(tty + 5, m->scheduled_shutdown_tty);
+        return !streq(p, m->scheduled_shutdown_tty);
 }
 
 static int warn_wall(Manager *m, usec_t n) {
@@ -138,10 +124,18 @@ static int wall_message_timeout_handler(
 int manager_setup_wall_message_timer(Manager *m) {
 
         usec_t n, elapse;
+#if 1 /// let's fix double wall messages in elogind - they suck.
+        usec_t left;
+#endif // 1
         int r;
 
         assert(m);
 
+#if 1 /// Make elogind more aware of the possibility to disable wall messages
+        /* Do not do anything if wall messages aren't enabled */
+        if (!m->enable_wall_messages)
+                return 0;
+#endif // 1
         n = now(CLOCK_REALTIME);
         elapse = m->scheduled_shutdown_timeout;
 
@@ -155,6 +149,7 @@ int manager_setup_wall_message_timer(Manager *m) {
         if (elapse < n)
                 return 0;
 
+#if 0 /// let's fix double wall messages in elogind - they suck.
         /* Warn immediately if less than 15 minutes are left */
         if (elapse - n < 15 * USEC_PER_MINUTE) {
                 r = warn_wall(m, n);
@@ -165,6 +160,23 @@ int manager_setup_wall_message_timer(Manager *m) {
         elapse = when_wall(n, elapse);
         if (elapse == 0)
                 return 0;
+#else
+        left = elapse - n;
+        elapse = when_wall(n, elapse);
+
+        /* Warn immediately if less than 15 minutes are left, but not if
+         * there aren't more than three seconds to the next timeout. */
+        if ( (left   < 15 * USEC_PER_MINUTE)
+          && (elapse >  3 * USEC_PER_SEC) ) {
+                r = warn_wall(m, n);
+                if (r == 0)
+                        return 0;
+        }
+
+        /* If the next timeout is within on second, delay it by 3 seconds */
+        if (USEC_PER_SEC > elapse)
+                elapse = 3 * USEC_PER_SEC;
+#endif // 0
 
         if (m->wall_message_timeout_source) {
                 r = sd_event_source_set_time(m->wall_message_timeout_source, n + elapse);