]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
timedate: print better errors when systemd-timesyncd.service unavailable
authorNick Rosbrook <enr0n@ubuntu.com>
Fri, 23 May 2025 21:10:02 +0000 (17:10 -0400)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 27 May 2025 19:40:08 +0000 (04:40 +0900)
If the error is a common bus error indicating the service is not
available, print a more user-friendly message indicating so.

src/timedate/timedatectl.c

index 36ec7bc833d1f4860839199cfe2d187ce7202cfd..44a64bb6b68ece705d0e37a63855546428a67f3a 100644 (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;
 }