summaryrefslogtreecommitdiff
path: root/src/udev
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-05-31 23:58:39 +0200
committerTom Gundersen <teg@jklm.no>2015-05-31 23:58:39 +0200
commit3d7dc8e4f9273ed0f14116ee7400718b7459df0d (patch)
tree9fecfa78a2239e339157f2a0c2e6f38d9d86d14f /src/udev
parent49f997f3bcf3ff6a1d794dfb8fbd3907d653dc33 (diff)
udevd: open sockets before forking
The communication channels must all be opened before forknig in daemon mode, or we cannot guarantee that udevadm will work correctly as soon as udevd is started.
Diffstat (limited to 'src/udev')
-rw-r--r--src/udev/udevd.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index 5717edd435..34e88af539 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -1439,7 +1439,7 @@ static int parse_argv(int argc, char *argv[]) {
static int manager_new(Manager **ret) {
_cleanup_(manager_freep) Manager *manager = NULL;
- int r;
+ int r, fd_ctrl, fd_uevent;
assert(ret);
@@ -1464,18 +1464,6 @@ static int manager_new(Manager **ret) {
udev_list_node_init(&manager->events);
udev_list_init(manager->udev, &manager->properties, true);
- *ret = manager;
- manager = NULL;
-
- return 0;
-}
-
-static int manager_listen(Manager *manager) {
- sigset_t mask;
- int r, fd_worker, fd_ctrl, fd_uevent, one = 1;
-
- assert(manager);
-
r = systemd_fds(&fd_ctrl, &fd_uevent);
if (r >= 0) {
/* get control and netlink socket from systemd */
@@ -1516,6 +1504,18 @@ static int manager_listen(Manager *manager) {
if (r < 0)
return log_error_errno(EINVAL, "error binding udev control socket");
+ *ret = manager;
+ manager = NULL;
+
+ return 0;
+}
+
+static int manager_listen(Manager *manager) {
+ sigset_t mask;
+ int r, fd_worker, one = 1;
+
+ assert(manager);
+
/* unnamed socket from workers to the main daemon */
r = socketpair(AF_LOCAL, SOCK_DGRAM|SOCK_CLOEXEC, 0, manager->worker_watch);
if (r < 0)
@@ -1561,7 +1561,7 @@ static int manager_listen(Manager *manager) {
if (r < 0)
return log_error_errno(r, "error creating watchdog event source: %m");
- r = sd_event_add_io(manager->event, &manager->ctrl_event, fd_ctrl, EPOLLIN, on_ctrl_msg, manager);
+ r = sd_event_add_io(manager->event, &manager->ctrl_event, udev_ctrl_get_fd(manager->ctrl), EPOLLIN, on_ctrl_msg, manager);
if (r < 0)
return log_error_errno(r, "error creating ctrl event source: %m");
@@ -1577,7 +1577,7 @@ static int manager_listen(Manager *manager) {
if (r < 0)
return log_error_errno(r, "error creating inotify event source: %m");
- r = sd_event_add_io(manager->event, &manager->uevent_event, fd_uevent, EPOLLIN, on_uevent, manager);
+ r = sd_event_add_io(manager->event, &manager->uevent_event, udev_monitor_get_fd(manager->monitor), EPOLLIN, on_uevent, manager);
if (r < 0)
return log_error_errno(r, "error creating uevent event source: %m");