From: Yu Watanabe Date: Thu, 6 Apr 2023 19:26:19 +0000 (+0900) Subject: update-utmp: modernize get_startup_monotonic_time() X-Git-Tag: v254-rc1~391^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3950d8f693216ce755ddd2e4078018015d108ac4;p=thirdparty%2Fsystemd.git update-utmp: modernize get_startup_monotonic_time() This also downgrade error level, as the failure will be ignored. No functional change, just refactoring. --- diff --git a/src/update-utmp/update-utmp.c b/src/update-utmp/update-utmp.c index 8f2fa17e6bf..7121f304c75 100644 --- a/src/update-utmp/update-utmp.c +++ b/src/update-utmp/update-utmp.c @@ -45,20 +45,23 @@ static void context_clear(Context *c) { #endif } -static usec_t get_startup_monotonic_time(Context *c) { +static int get_startup_monotonic_time(Context *c, usec_t *ret) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; - usec_t t = 0; int r; assert(c); + assert(ret); + + r = bus_get_property_trivial( + c->bus, + bus_systemd_mgr, + "UserspaceTimestampMonotonic", + &error, + 't', ret); + if (r < 0) + return log_warning_errno(r, "Failed to get timestamp, ignoring: %s", bus_error_message(&error, r)); - r = bus_get_property_trivial(c->bus, bus_systemd_mgr, "UserspaceTimestampMonotonic", &error, 't', &t); - if (r < 0) { - log_error_errno(r, "Failed to get timestamp: %s", bus_error_message(&error, r)); - return 0; - } - - return t; + return 0; } static int get_current_runlevel(Context *c) { @@ -106,7 +109,7 @@ static int get_current_runlevel(Context *c) { static int on_reboot(int argc, char *argv[], void *userdata) { Context *c = ASSERT_PTR(userdata); - usec_t t, boottime; + usec_t t = 0, boottime; int r = 0, q; /* We finished start-up, so let's write the utmp record and send the audit msg. */ @@ -118,8 +121,8 @@ static int on_reboot(int argc, char *argv[], void *userdata) { r = log_error_errno(errno, "Failed to send audit message: %m"); #endif - /* If this call fails it will return 0, which utmp_put_reboot() will then fix to the current time. */ - t = get_startup_monotonic_time(c); + /* If this call fails, then utmp_put_reboot() will fix to the current time. */ + (void) get_startup_monotonic_time(c, &t); boottime = map_clock_usec(t, CLOCK_MONOTONIC, CLOCK_REALTIME); /* We query the recorded monotonic time here (instead of the system clock CLOCK_REALTIME), even * though we actually want the system clock time. That's because there's a likely chance that the