From ead0adb161bb07ae4d53e9834ff04248bea19f3f Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 10 Jun 2018 17:17:34 +0900 Subject: [PATCH] timedatectl: add 'show' command to display machine-readable output Closes #9249. --- man/timedatectl.xml | 30 ++++++++++++++++++++---------- src/shared/bus-util.c | 3 ++- src/timedate/timedatectl.c | 22 ++++++++++++++++++++++ 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/man/timedatectl.xml b/man/timedatectl.xml index b6caa54..1a5ba02 100644 --- a/man/timedatectl.xml +++ b/man/timedatectl.xml @@ -147,6 +147,16 @@ + show + + Show the same information as , but in machine readable form. + This command is intended to be used whenever computer-parsable output is required. + Use if you are looking for formatted human-readable output. + By default, empty properties are suppressed. Use to show those too. + To select specific properties to show, use . + + + set-time [TIME] Set the system clock to the specified time. @@ -207,11 +217,12 @@ - systemd-timesyncd Commands + + systemd-timesyncd Commands - The following commands are specific to - systemd-timesyncd.service8. - + The following commands are specific to + systemd-timesyncd.service8. + @@ -225,12 +236,11 @@ show-timesync - Show properties of the manager of - systemd-timesyncd.service8. - By default, empty properties are suppressed. Use to show those too. To select specific - properties to show, use . This command is intended to be used whenever - computer-parsable output is required. Use if you are looking for formatted - human-readable output. + Show the same information as , but in machine readable form. + This command is intended to be used whenever computer-parsable output is required. + Use if you are looking for formatted human-readable output. + By default, empty properties are suppressed. Use to show those too. + To select specific properties to show, use . diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index ddbc9d9..8880023 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -696,7 +696,8 @@ int bus_print_property(const char *name, sd_bus_message *m, bool value, bool all /* Yes, heuristics! But we can change this check * should it turn out to not be sufficient */ - if (endswith(name, "Timestamp") || STR_IN_SET(name, "NextElapseUSecRealtime", "LastTriggerUSec")) { + if (endswith(name, "Timestamp") || + STR_IN_SET(name, "NextElapseUSecRealtime", "LastTriggerUSec", "TimeUSec", "RTCTimeUSec")) { char timestamp[FORMAT_TIMESTAMP_MAX]; const char *t; diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c index f412082..e253355 100644 --- a/src/timedate/timedatectl.c +++ b/src/timedate/timedatectl.c @@ -168,6 +168,26 @@ static int show_status(int argc, char **argv, void *userdata) { return r; } +static int show_properties(int argc, char **argv, void *userdata) { + sd_bus *bus = userdata; + int r; + + assert(bus); + + r = bus_print_all_properties(bus, + "org.freedesktop.timedate1", + "/org/freedesktop/timedate1", + NULL, + arg_property, + arg_value, + arg_all, + NULL); + if (r < 0) + return bus_log_parse_error(r); + + return 0; +} + static int set_time(int argc, char **argv, void *userdata) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; bool relative = false, interactive = arg_ask_password; @@ -696,6 +716,7 @@ static int help(void) { "\n" "Commands:\n" " status Show current time settings\n" + " show Show properties of systemd-timedated\n" " set-time TIME Set system time\n" " set-timezone ZONE Set system time zone\n" " list-timezones Show known time zones\n" @@ -815,6 +836,7 @@ static int timedatectl_main(sd_bus *bus, int argc, char *argv[]) { static const Verb verbs[] = { { "status", VERB_ANY, 1, VERB_DEFAULT, show_status }, + { "show", VERB_ANY, 1, 0, show_properties }, { "set-time", 2, 2, 0, set_time }, { "set-timezone", 2, 2, 0, set_timezone }, { "list-timezones", VERB_ANY, 1, 0, list_timezones }, -- 2.7.4