]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udevadm: add --ping option to 'control' command
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 12 Jan 2019 22:44:38 +0000 (07:44 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 18 Jan 2019 15:10:01 +0000 (16:10 +0100)
This exposes `udev_ctrl_send_ping()`.

man/udevadm.xml
src/udev/udevadm-control.c

index 44be7b3f894b5117dc5f5bdf152e2e1d16ab72c7..e6d4a1b10818c139716f0a9c229f9ec2e139d7fa 100644 (file)
             same time.</para>
           </listitem>
         </varlistentry>
+        <varlistentry>
+          <term><option>--ping</option></term>
+          <listitem>
+            <para>Send a ping message to systemd-udevd and wait for the reply. This may be useful to check that
+            systemd-udevd daemon is running.</para>
+          </listitem>
+        </varlistentry>
         <varlistentry>
           <term><option>-t</option></term>
           <term><option>--timeout=</option><replaceable>seconds</replaceable></term>
index 4cd3eba1bc5afd19f1f63d157ae964ef6c4d716f..7cfc4c929d1e3368dd27535af43654878c26656a 100644 (file)
@@ -40,6 +40,7 @@ static int help(void) {
                "  -R --reload              Reload rules and databases\n"
                "  -p --property=KEY=VALUE  Set a global property for all events\n"
                "  -m --children-max=N      Maximum number of children\n"
+               "     --ping                Wait for udev to respond to a ping message\n"
                "  -t --timeout=SECONDS     Maximum time to block for a reply\n"
                , program_invocation_short_name);
 
@@ -51,19 +52,24 @@ int control_main(int argc, char *argv[], void *userdata) {
         usec_t timeout = 60 * USEC_PER_SEC;
         int c, r;
 
+        enum {
+                ARG_PING = 0x100,
+        };
+
         static const struct option options[] = {
-                { "exit",             no_argument,       NULL, 'e' },
-                { "log-priority",     required_argument, NULL, 'l' },
-                { "stop-exec-queue",  no_argument,       NULL, 's' },
-                { "start-exec-queue", no_argument,       NULL, 'S' },
-                { "reload",           no_argument,       NULL, 'R' },
-                { "reload-rules",     no_argument,       NULL, 'R' }, /* alias for -R */
-                { "property",         required_argument, NULL, 'p' },
-                { "env",              required_argument, NULL, 'p' }, /* alias for -p */
-                { "children-max",     required_argument, NULL, 'm' },
-                { "timeout",          required_argument, NULL, 't' },
-                { "version",          no_argument,       NULL, 'V' },
-                { "help",             no_argument,       NULL, 'h' },
+                { "exit",             no_argument,       NULL, 'e'      },
+                { "log-priority",     required_argument, NULL, 'l'      },
+                { "stop-exec-queue",  no_argument,       NULL, 's'      },
+                { "start-exec-queue", no_argument,       NULL, 'S'      },
+                { "reload",           no_argument,       NULL, 'R'      },
+                { "reload-rules",     no_argument,       NULL, 'R'      }, /* alias for -R */
+                { "property",         required_argument, NULL, 'p'      },
+                { "env",              required_argument, NULL, 'p'      }, /* alias for -p */
+                { "children-max",     required_argument, NULL, 'm'      },
+                { "ping",             no_argument,       NULL, ARG_PING },
+                { "timeout",          required_argument, NULL, 't'      },
+                { "version",          no_argument,       NULL, 'V'      },
+                { "help",             no_argument,       NULL, 'h'      },
                 {}
         };
 
@@ -135,6 +141,11 @@ int control_main(int argc, char *argv[], void *userdata) {
                                 return r;
                         break;
                 }
+                case ARG_PING:
+                        r = udev_ctrl_send_ping(uctrl, timeout);
+                        if (r < 0)
+                                return log_error_errno(r, "Failed to connect to udev daemon: %m");
+                        break;
                 case 't':
                         r = parse_sec(optarg, &timeout);
                         if (r < 0)