Skip to content

Commit

Permalink
Merge pull request systemd#10919 from yuwata/sd-device-monitor-fixes
Browse files Browse the repository at this point in the history
sd-device-monitor: several fixes
  • Loading branch information
poettering committed Nov 26, 2018
2 parents 4e93220 + 6acf1cc commit a0ee3d9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
23 changes: 13 additions & 10 deletions src/libsystemd/sd-device/device-monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 7 additions & 4 deletions src/udev/udevd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit a0ee3d9

Please sign in to comment.