]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logind: reduce scope of a few variables
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 30 May 2022 12:34:05 +0000 (14:34 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 1 Jun 2022 07:23:55 +0000 (09:23 +0200)
src/login/logind-dbus.c
src/login/logind-utmp.c

index 888d3f7906e088937969e61d7eafc37de93e3c4d..27cdc46096b8f9f8457fcb56e8a96870cf5a87f0 100644 (file)
@@ -1888,9 +1888,11 @@ static int method_do_shutdown_or_sleep(
                 if (r < 0)
                         return r;
                 if ((flags & ~SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_PUBLIC) != 0)
-                        return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid flags parameter");
+                        return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS,
+                                                "Invalid flags parameter");
                 if (a->handle != HANDLE_REBOOT && (flags & SD_LOGIND_REBOOT_VIA_KEXEC))
-                        return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Reboot via kexec is only applicable with reboot operations");
+                        return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS,
+                                                "Reboot via kexec is only applicable with reboot operations");
         } else {
                 /* Old style method: no flags parameter, but interactive bool passed as boolean in
                  * payload. Let's convert this argument to the new-style flags parameter for our internal
@@ -1919,7 +1921,8 @@ static int method_do_shutdown_or_sleep(
                                                 "Not enough swap space for hibernation");
                 if (r == 0)
                         return sd_bus_error_setf(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED,
-                                                 "Sleep verb \"%s\" not supported", sleep_operation_to_string(a->sleep_operation));
+                                                 "Sleep verb \"%s\" not supported",
+                                                 sleep_operation_to_string(a->sleep_operation));
                 if (r < 0)
                         return r;
         }
index dfae1aa2ebd67c014fed0ceec46b261efe8e07b2..36148aa5e7fb66ff6998308cc29b61e4eefd8f0d 100644 (file)
@@ -21,9 +21,6 @@
 #include "utmp-wtmp.h"
 
 _const_ static usec_t when_wall(usec_t n, usec_t elapse) {
-
-        usec_t left;
-        unsigned i;
         static const int wall_timers[] = {
                 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
                 25, 40, 55, 70, 100, 130, 150, 180,
@@ -33,9 +30,9 @@ _const_ static usec_t when_wall(usec_t n, usec_t elapse) {
         if (n >= elapse)
                 return 0;
 
-        left = elapse - n;
+        usec_t left = elapse - n;
 
-        for (i = 1; i < ELEMENTSOF(wall_timers); i++)
+        for (unsigned i = 1; i < ELEMENTSOF(wall_timers); i++)
                 if (wall_timers[i] * USEC_PER_MINUTE >= left)
                         return left - wall_timers[i-1] * USEC_PER_MINUTE;
 
@@ -59,8 +56,6 @@ bool logind_wall_tty_filter(const char *tty, void *userdata) {
 }
 
 static int warn_wall(Manager *m, usec_t n) {
-        _cleanup_free_ char *l = NULL, *username = NULL;
-        usec_t left;
         int r;
 
         assert(m);
@@ -68,7 +63,9 @@ static int warn_wall(Manager *m, usec_t n) {
         if (!m->enable_wall_messages || !m->scheduled_shutdown_action)
                 return 0;
 
-        left = m->scheduled_shutdown_timeout > n;
+        usec_t left = m->scheduled_shutdown_timeout > n;
+
+        _cleanup_free_ char *l = NULL, *username = NULL;
 
         r = asprintf(&l, "%s%sThe system will %s %s%s!",
                      strempty(m->wall_message),
@@ -92,20 +89,18 @@ static int wall_message_timeout_handler(
                         uint64_t usec,
                         void *userdata) {
 
-        Manager *m = userdata;
-        usec_t n, next;
+        Manager *m = ASSERT_PTR(userdata);
         int r;
 
-        assert(m);
         assert(s == m->wall_message_timeout_source);
 
-        n = now(CLOCK_REALTIME);
+        usec_t n = now(CLOCK_REALTIME);
 
         r = warn_wall(m, n);
         if (r == 0)
                 return 0;
 
-        next = when_wall(n, m->scheduled_shutdown_timeout);
+        usec_t next = when_wall(n, m->scheduled_shutdown_timeout);
         if (next > 0) {
                 r = sd_event_source_set_time(s, n + next);
                 if (r < 0)
@@ -120,14 +115,12 @@ static int wall_message_timeout_handler(
 }
 
 int manager_setup_wall_message_timer(Manager *m) {
-
-        usec_t n, elapse;
         int r;
 
         assert(m);
 
-        n = now(CLOCK_REALTIME);
-        elapse = m->scheduled_shutdown_timeout;
+        usec_t n = now(CLOCK_REALTIME);
+        usec_t elapse = m->scheduled_shutdown_timeout;
 
         /* wall message handling */