update-utmp: modernize get_startup_monotonic_time()

This also downgrade error level, as the failure will be ignored.

No functional change, just refactoring.
This commit is contained in:
Yu Watanabe
2023-05-24 20:06:07 +09:00
parent 309491e4cf
commit 3950d8f693
+14 -11
View File
@@ -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', &t);
if (r < 0) {
log_error_errno(r, "Failed to get timestamp: %s", bus_error_message(&error, r));
return 0;
}
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));
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