d9b91f
From 86c3bece38bcf55da6387d20c6f01da9ad0284dc Mon Sep 17 00:00:00 2001
d9b91f
From: Tom Gundersen <teg@jklm.no>
d9b91f
Date: Wed, 27 May 2015 18:39:36 +0200
d9b91f
Subject: [PATCH] udevd: fix SIGCHLD handling in --daemon mode
d9b91f
d9b91f
We were listening for SIGCHLD in the wrong process.
d9b91f
---
d9b91f
 src/udev/udevd.c | 33 ++++++++++++++++++++++-----------
d9b91f
 1 file changed, 22 insertions(+), 11 deletions(-)
d9b91f
d9b91f
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
d9b91f
index 87e677e..299fda8 100644
d9b91f
--- a/src/udev/udevd.c
d9b91f
+++ b/src/udev/udevd.c
d9b91f
@@ -1288,13 +1288,6 @@ static int parse_argv(int argc, char *argv[]) {
d9b91f
 
d9b91f
 static int manager_new(Manager **ret) {
d9b91f
         _cleanup_(manager_freep) Manager *manager = NULL;
d9b91f
-        struct epoll_event ep_ctrl = { .events = EPOLLIN };
d9b91f
-        struct epoll_event ep_inotify = { .events = EPOLLIN };
d9b91f
-        struct epoll_event ep_signal = { .events = EPOLLIN };
d9b91f
-        struct epoll_event ep_netlink = { .events = EPOLLIN };
d9b91f
-        struct epoll_event ep_worker = { .events = EPOLLIN };
d9b91f
-        sigset_t mask;
d9b91f
-        int r, one = 1;
d9b91f
 
d9b91f
         assert(ret);
d9b91f
 
d9b91f
@@ -1323,6 +1316,23 @@ static int manager_new(Manager **ret) {
d9b91f
         udev_list_node_init(&manager->events);
d9b91f
         udev_list_init(manager->udev, &manager->properties, true);
d9b91f
 
d9b91f
+        *ret = manager;
d9b91f
+        manager = NULL;
d9b91f
+
d9b91f
+        return 0;
d9b91f
+}
d9b91f
+
d9b91f
+static int manager_listen(Manager *manager) {
d9b91f
+        struct epoll_event ep_ctrl = { .events = EPOLLIN };
d9b91f
+        struct epoll_event ep_inotify = { .events = EPOLLIN };
d9b91f
+        struct epoll_event ep_signal = { .events = EPOLLIN };
d9b91f
+        struct epoll_event ep_netlink = { .events = EPOLLIN };
d9b91f
+        struct epoll_event ep_worker = { .events = EPOLLIN };
d9b91f
+        sigset_t mask;
d9b91f
+        int r, one = 1;
d9b91f
+
d9b91f
+        assert(manager);
d9b91f
+
d9b91f
         r = systemd_fds(&manager->fd_ctrl, &manager->fd_uevent);
d9b91f
         if (r >= 0) {
d9b91f
                 /* get control and netlink socket from systemd */
d9b91f
@@ -1404,10 +1414,7 @@ static int manager_new(Manager **ret) {
d9b91f
             epoll_ctl(manager->fd_ep, EPOLL_CTL_ADD, manager->fd_worker, &ep_worker) < 0)
d9b91f
                 return log_error_errno(errno, "fail to add fds to epoll: %m");
d9b91f
 
d9b91f
-        *ret = manager;
d9b91f
-        manager = NULL;
d9b91f
-
d9b91f
-        return 1;
d9b91f
+        return 0;
d9b91f
 }
d9b91f
 
d9b91f
 int main(int argc, char *argv[]) {
d9b91f
@@ -1518,6 +1525,10 @@ int main(int argc, char *argv[]) {
d9b91f
         } else
d9b91f
                 sd_notify(1, "READY=1");
d9b91f
 
d9b91f
+        r = manager_listen(manager);
d9b91f
+        if (r < 0)
d9b91f
+                return log_error_errno(r, "failed to set up fds and listen for events: %m");
d9b91f
+
d9b91f
         for (;;) {
d9b91f
                 static usec_t last_usec;
d9b91f
                 struct epoll_event ev[8];
d9b91f
-- 
d9b91f
2.3.1
d9b91f