]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
timedatectl: add 'show' command to display machine-readable output
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 10 Jun 2018 08:17:34 +0000 (17:17 +0900)
committerLennart Poettering <lennart@poettering.net>
Thu, 14 Jun 2018 08:19:08 +0000 (10:19 +0200)
Closes #9249.

man/timedatectl.xml
src/shared/bus-util.c
src/timedate/timedatectl.c

index b6caa5458ddc1eff053c08c8e151058ad16f833e..1a5ba022e5c6f65e7a981660cba8a93f8098eff6 100644 (file)
         </para></listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><command>show</command></term>
+
+        <listitem><para>Show the same information as <option>status</option>, but in machine readable form.
+        This command is intended to be used whenever computer-parsable output is required.
+        Use <option>status</option> if you are looking for formatted human-readable output.</para>
+        <para>By default, empty properties are suppressed. Use <option>--all</option> to show those too.
+        To select specific properties to show, use <option>--property=</option>.</para></listitem>
+      </varlistentry>
+
       <varlistentry>
         <term><command>set-time [TIME]</command></term>
 
 
     </variablelist>
 
-    <refsect2><title>systemd-timesyncd Commands</title>
+    <refsect2>
+      <title>systemd-timesyncd Commands</title>
 
-    <para>The following commands are specific to
-    <citerefentry><refentrytitle>systemd-timesyncd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
-    </para>
+      <para>The following commands are specific to
+      <citerefentry><refentrytitle>systemd-timesyncd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
+      </para>
 
       <variablelist>
         <varlistentry>
         <varlistentry>
           <term><command>show-timesync</command></term>
 
-          <listitem><para>Show properties of the manager of
-          <citerefentry><refentrytitle>systemd-timesyncd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
-          By default, empty properties are suppressed. Use <option>--all</option> to show those too. To select specific
-          properties to show, use <option>--property=</option>. This command is intended to be used whenever
-          computer-parsable output is required. Use <option>timesync-status</option> if you are looking for formatted
-          human-readable output.</para></listitem>
+          <listitem><para>Show the same information as <option>timesync-status</option>, but in machine readable form.
+          This command is intended to be used whenever computer-parsable output is required.
+          Use <option>timesync-status</option> if you are looking for formatted human-readable output.</para>
+          <para>By default, empty properties are suppressed. Use <option>--all</option> to show those too.
+          To select specific properties to show, use <option>--property=</option>.</para></listitem>
         </varlistentry>
       </variablelist>
 
index ddbc9d934efa7a3489b5334875b901ed7a8a7586..888002368ad5f6f7573db3dc9f23a46a0de5aa20 100644 (file)
@@ -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;
 
index f4120822656d103aead5f7710551020cfa0b11a1..e253355405a9e2faf3d1c0cf077b63b644a4c2a4 100644 (file)
@@ -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       },