1 /* SPDX-License-Identifier: LGPL-2.1+ */
11 #include "bus-error.h"
13 #include "in-addr-util.h"
15 #include "parse-util.h"
16 #include "spawn-polkit-agent.h"
17 #include "sparse-endian.h"
18 #include "string-table.h"
20 #include "terminal-util.h"
24 static bool arg_no_pager
= false;
25 static bool arg_ask_password
= true;
26 static BusTransport arg_transport
= BUS_TRANSPORT_LOCAL
;
27 static char *arg_host
= NULL
;
28 static bool arg_adjust_system_clock
= false;
29 static bool arg_monitor
= false;
30 static char **arg_property
= NULL
;
31 static bool arg_value
= false;
32 static bool arg_all
= false;
34 typedef struct StatusInfo
{
46 static void print_status_info(const StatusInfo
*i
) {
47 const char *old_tz
= NULL
, *tz
;
48 bool have_time
= false;
57 /* Save the old $TZ */
63 if (setenv("TZ", isempty(i
->timezone
) ? "UTC" : i
->timezone
, true) < 0)
64 log_warning_errno(errno
, "Failed to set TZ environment variable, ignoring: %m");
69 sec
= (time_t) (i
->time
/ USEC_PER_SEC
);
71 } else if (IN_SET(arg_transport
, BUS_TRANSPORT_LOCAL
, BUS_TRANSPORT_MACHINE
)) {
75 log_warning("Could not get time from timedated and not operating locally, ignoring.");
78 n
= strftime(a
, sizeof a
, "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&sec
, &tm
));
79 printf(" Local time: %s\n", n
> 0 ? a
: "n/a");
81 n
= strftime(a
, sizeof a
, "%a %Y-%m-%d %H:%M:%S UTC", gmtime_r(&sec
, &tm
));
82 printf(" Universal time: %s\n", n
> 0 ? a
: "n/a");
84 printf(" Local time: %s\n", "n/a");
85 printf(" Universal time: %s\n", "n/a");
88 if (i
->rtc_time
> 0) {
91 rtc_sec
= (time_t) (i
->rtc_time
/ USEC_PER_SEC
);
92 n
= strftime(a
, sizeof a
, "%a %Y-%m-%d %H:%M:%S", gmtime_r(&rtc_sec
, &tm
));
93 printf(" RTC time: %s\n", n
> 0 ? a
: "n/a");
95 printf(" RTC time: %s\n", "n/a");
98 n
= strftime(a
, sizeof a
, "%Z, %z", localtime_r(&sec
, &tm
));
100 /* Restore the $TZ */
102 r
= setenv("TZ", old_tz
, true);
106 log_warning_errno(errno
, "Failed to set TZ environment variable, ignoring: %m");
110 printf(" Time zone: %s (%s)\n"
111 "System clock synchronized: %s\n"
113 " RTC in local TZ: %s\n",
114 strna(i
->timezone
), have_time
&& n
> 0 ? a
: "n/a",
115 yes_no(i
->ntp_synced
),
116 i
->ntp_capable
? (i
->ntp_active
? "active" : "inactive") : "n/a",
117 yes_no(i
->rtc_local
));
121 "Warning: The system is configured to read the RTC time in the local time zone.\n"
122 " This mode cannot be fully supported. It will create various problems\n"
123 " with time zone changes and daylight saving time adjustments. The RTC\n"
124 " time is never updated, it relies on external facilities to maintain it.\n"
125 " If at all possible, use RTC in UTC by calling\n"
126 " 'timedatectl set-local-rtc 0'.%s\n", ansi_highlight(), ansi_normal());
129 static int show_status(int argc
, char **argv
, void *userdata
) {
130 StatusInfo info
= {};
131 static const struct bus_properties_map map
[] = {
132 { "Timezone", "s", NULL
, offsetof(StatusInfo
, timezone
) },
133 { "LocalRTC", "b", NULL
, offsetof(StatusInfo
, rtc_local
) },
134 { "NTP", "b", NULL
, offsetof(StatusInfo
, ntp_active
) },
135 { "CanNTP", "b", NULL
, offsetof(StatusInfo
, ntp_capable
) },
136 { "NTPSynchronized", "b", NULL
, offsetof(StatusInfo
, ntp_synced
) },
137 { "TimeUSec", "t", NULL
, offsetof(StatusInfo
, time
) },
138 { "RTCTimeUSec", "t", NULL
, offsetof(StatusInfo
, rtc_time
) },
142 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
143 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
144 sd_bus
*bus
= userdata
;
149 r
= bus_map_all_properties(bus
,
150 "org.freedesktop.timedate1",
151 "/org/freedesktop/timedate1",
153 BUS_MAP_BOOLEAN_AS_BOOL
,
158 return log_error_errno(r
, "Failed to query server: %s", bus_error_message(&error
, r
));
160 print_status_info(&info
);
165 static int show_properties(int argc
, char **argv
, void *userdata
) {
166 sd_bus
*bus
= userdata
;
171 r
= bus_print_all_properties(bus
,
172 "org.freedesktop.timedate1",
173 "/org/freedesktop/timedate1",
180 return bus_log_parse_error(r
);
185 static int set_time(int argc
, char **argv
, void *userdata
) {
186 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
187 bool relative
= false, interactive
= arg_ask_password
;
188 sd_bus
*bus
= userdata
;
192 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
194 r
= parse_timestamp(argv
[1], &t
);
196 return log_error_errno(r
, "Failed to parse time specification '%s': %m", argv
[1]);
198 r
= sd_bus_call_method(bus
,
199 "org.freedesktop.timedate1",
200 "/org/freedesktop/timedate1",
201 "org.freedesktop.timedate1",
205 "xbb", (int64_t) t
, relative
, interactive
);
207 return log_error_errno(r
, "Failed to set time: %s", bus_error_message(&error
, r
));
212 static int set_timezone(int argc
, char **argv
, void *userdata
) {
213 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
214 sd_bus
*bus
= userdata
;
217 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
219 r
= sd_bus_call_method(bus
,
220 "org.freedesktop.timedate1",
221 "/org/freedesktop/timedate1",
222 "org.freedesktop.timedate1",
226 "sb", argv
[1], arg_ask_password
);
228 return log_error_errno(r
, "Failed to set time zone: %s", bus_error_message(&error
, r
));
233 static int set_local_rtc(int argc
, char **argv
, void *userdata
) {
234 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
235 sd_bus
*bus
= userdata
;
238 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
240 b
= parse_boolean(argv
[1]);
242 return log_error_errno(b
, "Failed to parse local RTC setting '%s': %m", argv
[1]);
244 r
= sd_bus_call_method(bus
,
245 "org.freedesktop.timedate1",
246 "/org/freedesktop/timedate1",
247 "org.freedesktop.timedate1",
251 "bbb", b
, arg_adjust_system_clock
, arg_ask_password
);
253 return log_error_errno(r
, "Failed to set local RTC: %s", bus_error_message(&error
, r
));
258 static int set_ntp(int argc
, char **argv
, void *userdata
) {
259 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
260 sd_bus
*bus
= userdata
;
263 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
265 b
= parse_boolean(argv
[1]);
267 return log_error_errno(b
, "Failed to parse NTP setting '%s': %m", argv
[1]);
269 r
= sd_bus_call_method(bus
,
270 "org.freedesktop.timedate1",
271 "/org/freedesktop/timedate1",
272 "org.freedesktop.timedate1",
276 "bb", b
, arg_ask_password
);
278 return log_error_errno(r
, "Failed to set ntp: %s", bus_error_message(&error
, r
));
283 static int list_timezones(int argc
, char **argv
, void *userdata
) {
284 _cleanup_strv_free_
char **zones
= NULL
;
287 r
= get_timezones(&zones
);
289 return log_error_errno(r
, "Failed to read list of time zones: %m");
291 (void) pager_open(arg_no_pager
, false);
297 typedef struct NTPStatusInfo
{
298 const char *server_name
;
299 char *server_address
;
300 usec_t poll_interval
, poll_max
, poll_min
;
301 usec_t root_distance_max
;
303 uint32_t leap
, version
, mode
, stratum
;
305 usec_t root_delay
, root_dispersion
;
310 usec_t origin
, recv
, trans
, dest
;
313 uint64_t packet_count
;
319 static void ntp_status_info_clear(NTPStatusInfo
*p
) {
320 p
->server_address
= mfree(p
->server_address
);
323 static const char * const ntp_leap_table
[4] = {
325 [1] = "last minute of the day has 61 seconds",
326 [2] = "last minute of the day has 59 seconds",
327 [3] = "not synchronized",
330 #pragma GCC diagnostic push
331 #pragma GCC diagnostic ignored "-Wtype-limits"
332 DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(ntp_leap
, uint32_t);
333 #pragma GCC diagnostic pop
335 static void print_ntp_status_info(NTPStatusInfo
*i
) {
336 char ts
[FORMAT_TIMESPAN_MAX
], tmin
[FORMAT_TIMESPAN_MAX
], tmax
[FORMAT_TIMESPAN_MAX
];
337 usec_t delay
, t14
, t23
, offset
, root_distance
;
343 * "Timestamp Name ID When Generated
344 * ------------------------------------------------------------
345 * Originate Timestamp T1 time request sent by client
346 * Receive Timestamp T2 time request received by server
347 * Transmit Timestamp T3 time reply sent by server
348 * Destination Timestamp T4 time reply received by client
350 * The round-trip delay, d, and system clock offset, t, are defined as:
351 * d = (T4 - T1) - (T3 - T2) t = ((T2 - T1) + (T3 - T4)) / 2"
354 printf(" Server: %s (%s)\n",
355 i
->server_address
, i
->server_name
);
356 printf("Poll interval: %s (min: %s; max %s)\n",
357 format_timespan(ts
, sizeof(ts
), i
->poll_interval
, 0),
358 format_timespan(tmin
, sizeof(tmin
), i
->poll_min
, 0),
359 format_timespan(tmax
, sizeof(tmax
), i
->poll_max
, 0));
361 if (i
->packet_count
== 0) {
362 printf(" Packet count: 0\n");
366 if (i
->dest
< i
->origin
|| i
->trans
< i
->recv
|| i
->dest
- i
->origin
< i
->trans
- i
->recv
) {
367 log_error("Invalid NTP response");
371 delay
= (i
->dest
- i
->origin
) - (i
->trans
- i
->recv
);
373 t14
= i
->origin
+ i
->dest
;
374 t23
= i
->recv
+ i
->trans
;
375 offset_sign
= t14
< t23
;
376 offset
= (offset_sign
? t23
- t14
: t14
- t23
) / 2;
378 root_distance
= i
->root_delay
/ 2 + i
->root_dispersion
;
381 " Version: %" PRIu32
"\n"
382 " Stratum: %" PRIu32
"\n",
383 ntp_leap_to_string(i
->leap
),
387 printf(" Reference: %s\n", i
->reference
.str
);
389 printf(" Reference: %" PRIX32
"\n", be32toh(i
->reference
.val
));
390 printf(" Precision: %s (%" PRIi32
")\n",
391 format_timespan(ts
, sizeof(ts
), DIV_ROUND_UP((nsec_t
) (exp2(i
->precision
) * NSEC_PER_SEC
), NSEC_PER_USEC
), 0),
393 printf("Root distance: %s (max: %s)\n",
394 format_timespan(ts
, sizeof(ts
), root_distance
, 0),
395 format_timespan(tmax
, sizeof(tmax
), i
->root_distance_max
, 0));
396 printf(" Offset: %s%s\n",
397 offset_sign
? "+" : "-",
398 format_timespan(ts
, sizeof(ts
), offset
, 0));
399 printf(" Delay: %s\n",
400 format_timespan(ts
, sizeof(ts
), delay
, 0));
401 printf(" Jitter: %s\n",
402 format_timespan(ts
, sizeof(ts
), i
->jitter
, 0));
403 printf(" Packet count: %" PRIu64
"\n", i
->packet_count
);
406 printf(" Frequency: %+.3fppm\n",
407 (double) i
->freq
/ 0x10000);
410 static int map_server_address(sd_bus
*bus
, const char *member
, sd_bus_message
*m
, sd_bus_error
*error
, void *userdata
) {
411 char **p
= (char **) userdata
;
418 r
= sd_bus_message_enter_container(m
, 'r', "iay");
422 r
= sd_bus_message_read(m
, "i", &family
);
426 r
= sd_bus_message_read_array(m
, 'y', &d
, &sz
);
430 r
= sd_bus_message_exit_container(m
);
434 if (sz
== 0 && family
== AF_UNSPEC
) {
439 if (!IN_SET(family
, AF_INET
, AF_INET6
)) {
440 log_error("Unknown address family %i", family
);
444 if (sz
!= FAMILY_ADDRESS_SIZE(family
)) {
445 log_error("Invalid address size");
449 r
= in_addr_to_string(family
, d
, p
);
456 static int map_ntp_message(sd_bus
*bus
, const char *member
, sd_bus_message
*m
, sd_bus_error
*error
, void *userdata
) {
457 NTPStatusInfo
*p
= userdata
;
465 r
= sd_bus_message_enter_container(m
, 'r', "uuuuittayttttbtt");
469 r
= sd_bus_message_read(m
, "uuuuitt",
470 &p
->leap
, &p
->version
, &p
->mode
, &p
->stratum
, &p
->precision
,
471 &p
->root_delay
, &p
->root_dispersion
);
475 r
= sd_bus_message_read_array(m
, 'y', &d
, &sz
);
479 r
= sd_bus_message_read(m
, "ttttbtt",
480 &p
->origin
, &p
->recv
, &p
->trans
, &p
->dest
,
481 &b
, &p
->packet_count
, &p
->jitter
);
485 r
= sd_bus_message_exit_container(m
);
492 memcpy(p
->reference
.str
, d
, sz
);
499 static int show_timesync_status_once(sd_bus
*bus
) {
500 static const struct bus_properties_map map_timesync
[] = {
501 { "ServerName", "s", NULL
, offsetof(NTPStatusInfo
, server_name
) },
502 { "ServerAddress", "(iay)", map_server_address
, offsetof(NTPStatusInfo
, server_address
) },
503 { "PollIntervalUSec", "t", NULL
, offsetof(NTPStatusInfo
, poll_interval
) },
504 { "PollIntervalMinUSec", "t", NULL
, offsetof(NTPStatusInfo
, poll_min
) },
505 { "PollIntervalMaxUSec", "t", NULL
, offsetof(NTPStatusInfo
, poll_max
) },
506 { "RootDistanceMaxUSec", "t", NULL
, offsetof(NTPStatusInfo
, root_distance_max
) },
507 { "NTPMessage", "(uuuuittayttttbtt)", map_ntp_message
, 0 },
508 { "Frequency", "x", NULL
, offsetof(NTPStatusInfo
, freq
) },
511 _cleanup_(ntp_status_info_clear
) NTPStatusInfo info
= {};
512 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
513 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
518 r
= bus_map_all_properties(bus
,
519 "org.freedesktop.timesync1",
520 "/org/freedesktop/timesync1",
522 BUS_MAP_BOOLEAN_AS_BOOL
,
527 return log_error_errno(r
, "Failed to query server: %s", bus_error_message(&error
, r
));
529 if (arg_monitor
&& !terminal_is_dumb())
530 fputs(ANSI_HOME_CLEAR
, stdout
);
532 print_ntp_status_info(&info
);
537 static int on_properties_changed(sd_bus_message
*m
, void *userdata
, sd_bus_error
*error
) {
543 r
= sd_bus_message_read(m
, "s", &name
);
545 return log_error_errno(r
, "Failed to read interface name: %m");
547 if (!streq_ptr(name
, "org.freedesktop.timesync1.Manager"))
550 return show_timesync_status_once(sd_bus_message_get_bus(m
));
553 static int show_timesync_status(int argc
, char **argv
, void *userdata
) {
554 _cleanup_(sd_event_unrefp
) sd_event
*event
= NULL
;
555 sd_bus
*bus
= userdata
;
560 r
= show_timesync_status_once(bus
);
567 r
= sd_event_default(&event
);
569 return log_error_errno(r
, "Failed to get event loop: %m");
571 r
= sd_bus_match_signal(bus
,
573 "org.freedesktop.timesync1",
574 "/org/freedesktop/timesync1",
575 "org.freedesktop.DBus.Properties",
577 on_properties_changed
, NULL
);
579 return log_error_errno(r
, "Failed to request match for PropertiesChanged signal: %m");
581 r
= sd_bus_attach_event(bus
, event
, SD_EVENT_PRIORITY_NORMAL
);
583 return log_error_errno(r
, "Failed to attach bus to event loop: %m");
585 r
= sd_event_loop(event
);
587 return log_error_errno(r
, "Failed to run event loop: %m");
592 #define property(name, fmt, ...) \
595 printf(fmt "\n", __VA_ARGS__); \
597 printf("%s=" fmt "\n", name, __VA_ARGS__); \
600 static int print_timesync_property(const char *name
, sd_bus_message
*m
, bool value
, bool all
) {
602 const char *contents
;
608 r
= sd_bus_message_peek_type(m
, &type
, &contents
);
614 case SD_BUS_TYPE_STRUCT
:
615 if (streq(name
, "NTPMessage")) {
616 _cleanup_(ntp_status_info_clear
) NTPStatusInfo i
= {};
617 char ts
[FORMAT_TIMESPAN_MAX
], stamp
[FORMAT_TIMESTAMP_MAX
];
619 r
= map_ntp_message(NULL
, NULL
, m
, NULL
, &i
);
623 if (i
.packet_count
== 0)
631 printf("{ Leap=%u, Version=%u, Mode=%u, Stratum=%u, Precision=%i,",
632 i
.leap
, i
.version
, i
.mode
, i
.stratum
, i
.precision
);
633 printf(" RootDelay=%s,",
634 format_timespan(ts
, sizeof(ts
), i
.root_delay
, 0));
635 printf(" RootDispersion=%s,",
636 format_timespan(ts
, sizeof(ts
), i
.root_dispersion
, 0));
639 printf(" Reference=%s,", i
.reference
.str
);
641 printf(" Reference=%" PRIX32
",", be32toh(i
.reference
.val
));
643 printf(" OriginateTimestamp=%s,",
644 format_timestamp(stamp
, sizeof(stamp
), i
.origin
));
645 printf(" ReceiveTimestamp=%s,",
646 format_timestamp(stamp
, sizeof(stamp
), i
.recv
));
647 printf(" TransmitTimestamp=%s,",
648 format_timestamp(stamp
, sizeof(stamp
), i
.trans
));
649 printf(" DestinationTimestamp=%s,",
650 format_timestamp(stamp
, sizeof(stamp
), i
.dest
));
651 printf(" Ignored=%s PacketCount=%" PRIu64
",",
652 yes_no(i
.spike
), i
.packet_count
);
653 printf(" Jitter=%s }\n",
654 format_timespan(ts
, sizeof(ts
), i
.jitter
, 0));
658 } else if (streq(name
, "ServerAddress")) {
659 _cleanup_free_
char *str
= NULL
;
661 r
= map_server_address(NULL
, NULL
, m
, NULL
, &str
);
665 if (arg_all
|| !isempty(str
))
666 property(name
, "%s", str
);
676 static int show_timesync(int argc
, char **argv
, void *userdata
) {
677 sd_bus
*bus
= userdata
;
682 r
= bus_print_all_properties(bus
,
683 "org.freedesktop.timesync1",
684 "/org/freedesktop/timesync1",
685 print_timesync_property
,
691 return bus_log_parse_error(r
);
696 static int help(void) {
697 printf("%s [OPTIONS...] COMMAND ...\n\n"
698 "Query or change system time and date settings.\n\n"
699 " -h --help Show this help message\n"
700 " --version Show package version\n"
701 " --no-pager Do not pipe output into a pager\n"
702 " --no-ask-password Do not prompt for password\n"
703 " -H --host=[USER@]HOST Operate on remote host\n"
704 " -M --machine=CONTAINER Operate on local container\n"
705 " --adjust-system-clock Adjust system clock when changing local RTC mode\n"
706 " --monitor Monitor status of systemd-timesyncd\n"
707 " -p --property=NAME Show only properties by this name\n"
708 " -a --all Show all properties, including empty ones\n"
709 " --value When showing properties, only print the value\n"
712 " status Show current time settings\n"
713 " show Show properties of systemd-timedated\n"
714 " set-time TIME Set system time\n"
715 " set-timezone ZONE Set system time zone\n"
716 " list-timezones Show known time zones\n"
717 " set-local-rtc BOOL Control whether RTC is in local time\n"
718 " set-ntp BOOL Enable or disable network time synchronization\n"
720 "systemd-timesyncd Commands:\n"
721 " timesync-status Show status of systemd-timesyncd\n"
722 " show-timesync Show properties of systemd-timesyncd\n"
723 , program_invocation_short_name
);
728 static int verb_help(int argc
, char **argv
, void *userdata
) {
732 static int parse_argv(int argc
, char *argv
[]) {
737 ARG_ADJUST_SYSTEM_CLOCK
,
743 static const struct option options
[] = {
744 { "help", no_argument
, NULL
, 'h' },
745 { "version", no_argument
, NULL
, ARG_VERSION
},
746 { "no-pager", no_argument
, NULL
, ARG_NO_PAGER
},
747 { "host", required_argument
, NULL
, 'H' },
748 { "machine", required_argument
, NULL
, 'M' },
749 { "no-ask-password", no_argument
, NULL
, ARG_NO_ASK_PASSWORD
},
750 { "adjust-system-clock", no_argument
, NULL
, ARG_ADJUST_SYSTEM_CLOCK
},
751 { "monitor", no_argument
, NULL
, ARG_MONITOR
},
752 { "property", required_argument
, NULL
, 'p' },
753 { "all", no_argument
, NULL
, 'a' },
754 { "value", no_argument
, NULL
, ARG_VALUE
},
763 while ((c
= getopt_long(argc
, argv
, "hH:M:p:a", options
, NULL
)) >= 0)
774 arg_transport
= BUS_TRANSPORT_REMOTE
;
779 arg_transport
= BUS_TRANSPORT_MACHINE
;
783 case ARG_NO_ASK_PASSWORD
:
784 arg_ask_password
= false;
787 case ARG_ADJUST_SYSTEM_CLOCK
:
788 arg_adjust_system_clock
= true;
800 r
= strv_extend(&arg_property
, optarg
);
804 /* If the user asked for a particular
805 * property, show it to him, even if it is
823 assert_not_reached("Unhandled option");
829 static int timedatectl_main(sd_bus
*bus
, int argc
, char *argv
[]) {
831 static const Verb verbs
[] = {
832 { "status", VERB_ANY
, 1, VERB_DEFAULT
, show_status
},
833 { "show", VERB_ANY
, 1, 0, show_properties
},
834 { "set-time", 2, 2, 0, set_time
},
835 { "set-timezone", 2, 2, 0, set_timezone
},
836 { "list-timezones", VERB_ANY
, 1, 0, list_timezones
},
837 { "set-local-rtc", 2, 2, 0, set_local_rtc
},
838 { "set-ntp", 2, 2, 0, set_ntp
},
839 { "timesync-status", VERB_ANY
, 1, 0, show_timesync_status
},
840 { "show-timesync", VERB_ANY
, 1, 0, show_timesync
},
841 { "help", VERB_ANY
, VERB_ANY
, 0, verb_help
}, /* Not documented, but supported since it is created. */
845 return dispatch_verb(argc
, argv
, verbs
, bus
);
848 int main(int argc
, char *argv
[]) {
852 setlocale(LC_ALL
, "");
853 log_parse_environment();
856 r
= parse_argv(argc
, argv
);
860 r
= bus_connect_transport(arg_transport
, arg_host
, false, &bus
);
862 log_error_errno(r
, "Failed to create bus connection: %m");
866 r
= timedatectl_main(bus
, argc
, argv
);
869 /* make sure we terminate the bus connection first, and then close the
870 * pager, see issue #3543 for the details. */
871 sd_bus_flush_close_unref(bus
);
874 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;