timedate: print better errors when systemd-timesyncd.service unavailable

If the error is a common bus error indicating the service is not
available, print a more user-friendly message indicating so.
This commit is contained in:
Nick Rosbrook
2025-05-23 17:10:02 -04:00
committed by Yu Watanabe
parent 906145d53f
commit c6b4f1c8f8

View File

@@ -666,8 +666,14 @@ static int show_timesync_status_once(sd_bus *bus) {
&error,
&m,
&info);
if (r < 0)
if (r < 0) {
if (bus_error_is_unknown_service(&error))
return log_error_errno(r,
"Command requires systemd-timesyncd.service, but it is not available: %s",
bus_error_message(&error, r));
return log_error_errno(r, "Failed to query server: %s", bus_error_message(&error, r));
}
if (arg_monitor && !terminal_is_dumb())
fputs(ANSI_HOME_CLEAR, stdout);
@@ -798,6 +804,7 @@ static int print_timesync_property(const char *name, const char *expected_value,
}
static int show_timesync(int argc, char **argv, void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
sd_bus *bus = ASSERT_PTR(userdata);
int r;
@@ -807,9 +814,15 @@ static int show_timesync(int argc, char **argv, void *userdata) {
print_timesync_property,
arg_property,
arg_print_flags,
NULL);
if (r < 0)
&error);
if (r < 0) {
if (bus_error_is_unknown_service(&error))
return log_error_errno(r,
"Command requires systemd-timesyncd.service, but it is not available: %s",
bus_error_message(&error, r));
return bus_log_parse_error(r);
}
return 0;
}