From 08de195825cc1c93f0f3317a894830acdc2218b0 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 18 Nov 2019 20:56:33 +0900 Subject: [PATCH] udev: do not propagate error in executing PROGRAM and IMPORT{program} Also, this adds more logs. Fixes #14027. --- src/udev/udev-event.c | 4 +++- src/udev/udev-rules.c | 18 +++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index bff75ed5219..58d484280aa 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -1014,7 +1014,9 @@ void udev_event_execute_run(UdevEvent *event, usec_t timeout_usec) { log_device_debug(event->dev, "Running command \"%s\"", command); r = udev_event_spawn(event, timeout_usec, false, command, NULL, 0); - if (r > 0) /* returned value is positive when program fails */ + if (r < 0) + log_device_warning_errno(event->dev, r, "Failed to execute '%s', ignoring: %m", command); + else if (r > 0) /* returned value is positive when program fails */ log_device_debug(event->dev, "Command \"%s\" returned %d (error), ignoring.", command, r); } } diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index d215db8c57e..6168b332d3b 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -1665,10 +1665,13 @@ static int udev_rule_apply_token_to_event( log_rule_debug(dev, rules, "Running PROGRAM '%s'", buf); r = udev_event_spawn(event, timeout_usec, true, buf, result, sizeof(result)); - if (r < 0) - return log_rule_error_errno(dev, rules, r, "Failed to execute '%s': %m", buf); - if (r > 0) + if (r != 0) { + if (r < 0) + log_rule_warning_errno(dev, rules, r, "Failed to execute '%s', ignoring: %m", buf); + else /* returned value is positive when program fails */ + log_rule_debug(dev, rules, "Command \"%s\" returned %d (error), ignoring", buf, r); return token->op == OP_NOMATCH; + } delete_trailing_chars(result, "\n"); count = util_replace_chars(result, UDEV_ALLOWED_CHARS_INPUT); @@ -1732,10 +1735,11 @@ static int udev_rule_apply_token_to_event( log_rule_debug(dev, rules, "Importing properties from results of '%s'", buf); r = udev_event_spawn(event, timeout_usec, true, buf, result, sizeof result); - if (r < 0) - return log_rule_error_errno(dev, rules, r, "Failed to execute '%s': %m", buf); - if (r > 0) { - log_rule_debug(dev, rules, "Command \"%s\" returned %d (error), ignoring", buf, r); + if (r != 0) { + if (r < 0) + log_rule_warning_errno(dev, rules, r, "Failed to execute '%s', ignoring: %m", buf); + else /* returned value is positive when program fails */ + log_rule_debug(dev, rules, "Command \"%s\" returned %d (error), ignoring", buf, r); return token->op == OP_NOMATCH; }