| From: Yu Watanabe <watanabe.yu+github@gmail.com> |
| Date: Sun, 13 Jan 2019 07:44:38 +0900 |
| Subject: [PATCH] udevadm: add --ping option to 'control' command |
| |
| This exposes `udev_ctrl_send_ping()`. |
| --- |
| Ported from upstream commit a82340cc0312e2a946ac5c797fa57e98fe613ce7: |
| https://github.com/systemd/systemd/commit/a82340cc0312e2a946ac5c797fa57e98fe613ce7 |
| |
| * Minor changes required to match context that changed in between |
| v225 and the upstream commit. |
| * using 'rc' vs. 'r' variable, plus different return/break conventions |
| |
| man/udevadm.xml | 7 +++++++ |
| src/udev/udevadm-control.c | 35 ++++++++++++++++++++++++----------- |
| 2 files changed, 31 insertions(+), 11 deletions(-) |
| |
| diff --git a/man/udevadm.xml b/man/udevadm.xml |
| index 484cbac84dc4..f3c62fba6b1d 100644 |
| --- a/man/udevadm.xml |
| +++ b/man/udevadm.xml |
| @@ -450,6 +450,13 @@ |
| 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>--timeout=</option><replaceable>seconds</replaceable></term> |
| <listitem> |
| diff --git a/src/udev/udevadm-control.c b/src/udev/udevadm-control.c |
| index 78170463b653..edda91d2906d 100644 |
| --- a/src/udev/udevadm-control.c |
| +++ b/src/udev/udevadm-control.c |
| @@ -35,6 +35,7 @@ static void print_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" |
| " --timeout=SECONDS Maximum time to block for a reply\n" |
| , program_invocation_short_name); |
| } |
| @@ -44,18 +45,23 @@ static int adm_control(struct udev *udev, int argc, char *argv[]) { |
| int timeout = 60; |
| int rc = 1, c; |
| |
| + 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' }, |
| - { "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' }, |
| + { "help", no_argument, NULL, 'h' }, |
| {} |
| }; |
| |
| @@ -133,6 +139,15 @@ static int adm_control(struct udev *udev, int argc, char *argv[]) { |
| rc = 0; |
| break; |
| } |
| + case ARG_PING: |
| + rc = udev_ctrl_send_ping(uctrl, timeout); |
| + if (rc < 0) { |
| + log_error_errno(rc, "Failed to connect to udev daemon: %m"); |
| + rc = 2; |
| + } else { |
| + rc = 0; |
| + } |
| + break; |
| case 't': { |
| int seconds; |
| |
| -- |
| 2.29.2 |
| |