]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logind-dbus: correctly calculate when to create /etc/nologin file in all cases
authorLennart Poettering <lennart@poettering.net>
Tue, 1 Jun 2021 14:46:40 +0000 (16:46 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 1 Jun 2021 17:26:47 +0000 (19:26 +0200)
Fixes: #19258
src/login/logind-dbus.c

index e48360100c91f24d75bf5332b13b49daddc16a5f..2112e53393aa80980e9f01cad087cdc02d1a5b73 100644 (file)
@@ -2038,6 +2038,11 @@ static int nologin_timeout_handler(
         return 0;
 }
 
+static usec_t nologin_timeout_usec(usec_t elapse) {
+        /* Issue /run/nologin five minutes before shutdown */
+        return LESS_BY(elapse, 5 * USEC_PER_MINUTE);
+}
+
 static int update_schedule_file(Manager *m) {
         _cleanup_free_ char *temp_path = NULL;
         _cleanup_fclose_ FILE *f = NULL;
@@ -2238,7 +2243,7 @@ static int method_schedule_shutdown(sd_bus_message *message, void *userdata, sd_
         m->shutdown_dry_run = dry_run;
 
         if (m->nologin_timeout_source) {
-                r = sd_event_source_set_time(m->nologin_timeout_source, elapse);
+                r = sd_event_source_set_time(m->nologin_timeout_source, nologin_timeout_usec(elapse));
                 if (r < 0)
                         return log_error_errno(r, "sd_event_source_set_time() failed: %m");
 
@@ -2247,7 +2252,7 @@ static int method_schedule_shutdown(sd_bus_message *message, void *userdata, sd_
                         return log_error_errno(r, "sd_event_source_set_enabled() failed: %m");
         } else {
                 r = sd_event_add_time(m->event, &m->nologin_timeout_source,
-                                      CLOCK_REALTIME, elapse - 5 * USEC_PER_MINUTE, 0, nologin_timeout_handler, m);
+                                      CLOCK_REALTIME, nologin_timeout_usec(elapse), 0, nologin_timeout_handler, m);
                 if (r < 0)
                         return log_error_errno(r, "sd_event_add_time() failed: %m");
         }