From b280061314086d3cb84fc4709a4bad26341948d8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 30 May 2022 14:34:05 +0200 Subject: [PATCH] logind: reduce scope of a few variables --- src/login/logind-dbus.c | 9 ++++++--- src/login/logind-utmp.c | 27 ++++++++++----------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 888d3f7906..27cdc46096 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -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; } diff --git a/src/login/logind-utmp.c b/src/login/logind-utmp.c index dfae1aa2eb..36148aa5e7 100644 --- a/src/login/logind-utmp.c +++ b/src/login/logind-utmp.c @@ -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 */ -- 2.25.1