X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fsystemd.git;a=blobdiff_plain;f=src%2Fudev%2Fudevadm-trigger.c;h=f14010a2d0de3b368729856bb8917e9b552a72b5;hp=2a658158e61d0533919e97908d1cb78e50d51678;hb=4b381a9ef65d68dc79760b093436a9c81f43fa5d;hpb=5b3b0733c96b54df8bea040ccc13856a014c173f diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c index 2a658158e61..f14010a2d0d 100644 --- a/src/udev/udevadm-trigger.c +++ b/src/udev/udevadm-trigger.c @@ -7,6 +7,7 @@ #include "sd-event.h" #include "device-enumerator-private.h" +#include "device-private.h" #include "fd-util.h" #include "fileio.h" #include "path-util.h" @@ -24,7 +25,7 @@ static bool arg_dry_run = false; static int exec_list(sd_device_enumerator *e, const char *action, Set *settle_set) { sd_device *d; - int r; + int r, ret = 0; FOREACH_DEVICE_AND_SUBSYSTEM(e, d) { _cleanup_free_ char *filename = NULL; @@ -44,7 +45,10 @@ static int exec_list(sd_device_enumerator *e, const char *action, Set *settle_se r = write_string_file(filename, action, WRITE_STRING_FILE_DISABLE_BUFFER); if (r < 0) { - log_debug_errno(r, "Failed to write '%s' to '%s', ignoring: %m", action, filename); + log_full_errno(r == -ENOENT ? LOG_DEBUG : LOG_ERR, r, + "Failed to write '%s' to '%s': %m", action, filename); + if (ret == 0 && r != -ENOENT) + ret = r; continue; } @@ -55,10 +59,11 @@ static int exec_list(sd_device_enumerator *e, const char *action, Set *settle_se } } - return 0; + return ret; } static int device_monitor_handler(sd_device_monitor *m, sd_device *dev, void *userdata) { + _cleanup_free_ char *val = NULL; Set *settle_set = userdata; const char *syspath; @@ -71,7 +76,8 @@ static int device_monitor_handler(sd_device_monitor *m, sd_device *dev, void *us if (arg_verbose) printf("settle %s\n", syspath); - if (!set_remove(settle_set, syspath)) + val = set_remove(settle_set, syspath); + if (!val) log_debug("Got epoll event on syspath %s not present in syspath set", syspath); if (set_isempty(settle_set)) @@ -199,11 +205,10 @@ int trigger_main(int argc, char *argv[], void *userdata) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown type --type=%s", optarg); break; case 'c': - if (STR_IN_SET(optarg, "add", "remove", "change")) - action = optarg; - else - log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown action '%s'", optarg); + if (device_action_from_string(optarg) < 0) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown action '%s'", optarg); + action = optarg; break; case 's': r = sd_device_enumerator_add_match_subsystem(e, optarg, true); @@ -299,22 +304,20 @@ int trigger_main(int argc, char *argv[], void *userdata) { } } - if (!arg_dry_run || ping) { - r = must_be_root(); - if (r < 0) - return r; - } - if (ping) { _cleanup_(udev_ctrl_unrefp) struct udev_ctrl *uctrl = NULL; - uctrl = udev_ctrl_new(); - if (!uctrl) - return log_oom(); + r = udev_ctrl_new(&uctrl); + if (r < 0) + return log_error_errno(r, "Failed to initialize udev control: %m"); - r = udev_ctrl_send_ping(uctrl, ping_timeout_usec); + r = udev_ctrl_send_ping(uctrl); if (r < 0) return log_error_errno(r, "Failed to connect to udev daemon: %m"); + + r = udev_ctrl_wait(uctrl, ping_timeout_usec); + if (r < 0) + return log_error_errno(r, "Failed to wait for daemon to reply: %m"); } for (; optind < argc; optind++) {