diff --git a/src/libsystemd/sd-device/device-monitor.c b/src/libsystemd/sd-device/device-monitor.c index 05e7ec0715..8f2eec1bda 100644 --- a/src/libsystemd/sd-device/device-monitor.c +++ b/src/libsystemd/sd-device/device-monitor.c @@ -210,9 +210,11 @@ _public_ int sd_device_monitor_start(sd_device_monitor *m, sd_device_monitor_han return r; } - r = device_monitor_enable_receiving(m); - if (r < 0) - return r; + if (!m->bound) { + r = device_monitor_enable_receiving(m); + if (r < 0) + return r; + } m->callback = callback; m->userdata = userdata; @@ -246,7 +248,7 @@ _public_ int sd_device_monitor_attach_event(sd_device_monitor *m, sd_event *even else { r = sd_event_default(&m->event); if (r < 0) - return 0; + return r; } return 0; @@ -269,15 +271,13 @@ int device_monitor_enable_receiving(sd_device_monitor *m) { assert_return(m, -EINVAL); - if (!m->filter_uptodate) { - r = sd_device_monitor_filter_update(m); - if (r < 0) - return log_debug_errno(r, "sd-device-monitor: Failed to update filter: %m"); - } + r = sd_device_monitor_filter_update(m); + if (r < 0) + return log_debug_errno(r, "sd-device-monitor: Failed to update filter: %m"); if (!m->bound) { if (bind(m->sock, &m->snl.sa, sizeof(struct sockaddr_nl)) < 0) - return log_debug_errno(errno, "sd-device-monitor: Failed to bind monitoring socket to event source: %m"); + return log_debug_errno(errno, "sd-device-monitor: Failed to bind monitoring socket: %m"); m->bound = true; } @@ -595,6 +595,9 @@ _public_ int sd_device_monitor_filter_update(sd_device_monitor *m) { assert_return(m, -EINVAL); + if (m->filter_uptodate) + return 0; + if (hashmap_isempty(m->subsystem_filter) && set_isempty(m->tag_filter)) { m->filter_uptodate = true; diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 9c8e7f977f..c9e3d426b3 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -1616,9 +1616,11 @@ static int manager_new(Manager **ret, int fd_ctrl, int fd_uevent, const char *cg if (!manager->ctrl) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to initialize udev control socket"); - r = udev_ctrl_enable_receiving(manager->ctrl); - if (r < 0) - return log_error_errno(r, "Failed to bind udev control socket: %m"); + if (fd_ctrl < 0) { + r = udev_ctrl_enable_receiving(manager->ctrl); + if (r < 0) + return log_error_errno(r, "Failed to bind udev control socket: %m"); + } fd_ctrl = udev_ctrl_get_fd(manager->ctrl); if (fd_ctrl < 0) @@ -1628,7 +1630,8 @@ static int manager_new(Manager **ret, int fd_ctrl, int fd_uevent, const char *cg if (r < 0) return log_error_errno(r, "Failed to initialize device monitor: %m"); - (void) sd_device_monitor_set_receive_buffer_size(manager->monitor, 128 * 1024 * 1024); + if (fd_uevent < 0) + (void) sd_device_monitor_set_receive_buffer_size(manager->monitor, 128 * 1024 * 1024); /* unnamed socket from workers to the main daemon */ r = socketpair(AF_LOCAL, SOCK_DGRAM|SOCK_CLOEXEC, 0, manager->worker_watch);