X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Flogin%2Flogind-utmp.c;h=917aa72aa2fbed0a30797e596daf157f1dbd5c95;hp=1e13ff01de75c460aa0e915c0f8b46848d118a0e;hb=e271d1f29638c009e455a6e06e0865e01cf26f86;hpb=c6f9360e347fcd159edf75b3ebe1de7913fb83e4 diff --git a/src/login/logind-utmp.c b/src/login/logind-utmp.c index 1e13ff01d..917aa72aa 100644 --- a/src/login/logind-utmp.c +++ b/src/login/logind-utmp.c @@ -1,5 +1,3 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - /*** This file is part of systemd. @@ -20,20 +18,23 @@ ***/ #include +#include #include #include -#include #include "sd-messages.h" -#include "strv.h" -#include "special.h" -#include "unit-name.h" -#include "audit.h" -#include "bus-util.h" -#include "bus-error.h" + +#include "alloc-util.h" +#include "audit-util.h" #include "bus-common-errors.h" -#include "logind.h" +#include "bus-error.h" +#include "bus-util.h" #include "formats-util.h" +#include "logind.h" +//#include "special.h" +#include "strv.h" +#include "unit-name.h" +#include "user-util.h" #include "utmp-wtmp.h" _const_ static usec_t when_wall(usec_t n, usec_t elapse) { @@ -64,7 +65,7 @@ bool logind_wall_tty_filter(const char *tty, void *userdata) { assert(m); - if (!startswith(tty, "/dev/")) + if (!startswith(tty, "/dev/") || !m->scheduled_shutdown_tty) return true; return !streq(tty + 5, m->scheduled_shutdown_tty); @@ -73,7 +74,7 @@ bool logind_wall_tty_filter(const char *tty, void *userdata) { static int warn_wall(Manager *m, usec_t n) { char date[FORMAT_TIMESTAMP_MAX] = {}; _cleanup_free_ char *l = NULL; - usec_t left; + bool left; int r; assert(m); @@ -94,7 +95,7 @@ static int warn_wall(Manager *m, usec_t n) { return 0; } - utmp_wall(l, lookup_uid(m->scheduled_shutdown_uid), + utmp_wall(l, uid_to_name(m->scheduled_shutdown_uid), m->scheduled_shutdown_tty, logind_wall_tty_filter, m); return 1; @@ -135,10 +136,19 @@ 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; @@ -152,6 +162,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); @@ -162,6 +173,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);