[systemd-commits] 3 commits - src/udev

Tom Gundersen tomegun at kemper.freedesktop.org
Sun May 24 06:29:58 PDT 2015


 src/udev/udevd.c |   31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

New commits:
commit 040e689654ef08c63ab93bf0875865398e8d9c91
Author: Tom Gundersen <teg at jklm.no>
Date:   Sun May 24 15:20:36 2015 +0200

    udevd: event - fix event queue in daemenozied mode
    
    We would enforce that events could only be added to the queue from the
    main process, but that brake in daemonized mode. Relax the restriction
    to only allow one process to add events to the queue.
    
    Reported by Mantas Mikulėnas.

diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index 4a44b03..b33a262 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -564,7 +564,10 @@ static int event_queue_insert(Manager *manager, struct udev_device *dev) {
         assert(manager);
         assert(dev);
 
-        /* only the main process can add events to the queue */
+        /* only one process can add events to the queue */
+        if (manager->pid == 0)
+                manager->pid = getpid();
+
         assert(manager->pid == getpid());
 
         event = new0(struct event, 1);
@@ -1300,8 +1303,6 @@ static int manager_new(Manager **ret) {
         if (!manager)
                 return log_oom();
 
-        manager->pid = getpid();
-
         manager->fd_ep = -1;
         manager->fd_ctrl = -1;
         manager->fd_uevent = -1;

commit 2dd9f98d2d7a06a8e28729da6339fce50d66e9cc
Author: Tom Gundersen <teg at jklm.no>
Date:   Sun May 24 15:14:43 2015 +0200

    udevd: worker - modernize a bit
    
    Initialize structs when declaring rather than using memzero().

diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index d8cb046..4a44b03 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -316,10 +316,11 @@ static void worker_spawn(Manager *manager, struct event *event) {
         switch (pid) {
         case 0: {
                 struct udev_device *dev = NULL;
+                _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
                 int fd_monitor;
                 _cleanup_close_ int fd_signal = -1, fd_ep = -1;
-                _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
-                struct epoll_event ep_signal, ep_monitor;
+                struct epoll_event ep_signal = { .events = EPOLLIN };
+                struct epoll_event ep_monitor = { .events = EPOLLIN };
                 sigset_t mask;
                 int r = 0;
 
@@ -345,6 +346,10 @@ static void worker_spawn(Manager *manager, struct event *event) {
                         r = log_error_errno(errno, "error creating signalfd %m");
                         goto out;
                 }
+                ep_signal.data.fd = fd_signal;
+
+                fd_monitor = udev_monitor_get_fd(worker_monitor);
+                ep_monitor.data.fd = fd_monitor;
 
                 fd_ep = epoll_create1(EPOLL_CLOEXEC);
                 if (fd_ep < 0) {
@@ -352,15 +357,6 @@ static void worker_spawn(Manager *manager, struct event *event) {
                         goto out;
                 }
 
-                memzero(&ep_signal, sizeof(struct epoll_event));
-                ep_signal.events = EPOLLIN;
-                ep_signal.data.fd = fd_signal;
-
-                fd_monitor = udev_monitor_get_fd(worker_monitor);
-                memzero(&ep_monitor, sizeof(struct epoll_event));
-                ep_monitor.events = EPOLLIN;
-                ep_monitor.data.fd = fd_monitor;
-
                 if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_signal, &ep_signal) < 0 ||
                     epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_monitor, &ep_monitor) < 0) {
                         r = log_error_errno(errno, "fail to add fds to epoll: %m");

commit 6d1b1e0bc6bd020218afc5f05286bf372be283d5
Author: Tom Gundersen <teg at jklm.no>
Date:   Sun May 24 15:10:04 2015 +0200

    udevd: worker - fully clean up unnecessary fds
    
    These are only ever used in the parent process, so close them early in the worker.

diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index afd4640..d8cb046 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -329,11 +329,15 @@ static void worker_spawn(Manager *manager, struct event *event) {
 
                 manager_workers_free(manager);
                 event_queue_cleanup(manager, EVENT_UNDEF);
+
                 manager->monitor = udev_monitor_unref(manager->monitor);
+                manager->ctrl_conn_blocking = udev_ctrl_connection_unref(manager->ctrl_conn_blocking);
                 manager->ctrl = udev_ctrl_unref(manager->ctrl);
+
+                manager->fd_ep = safe_close(manager->fd_ep);
                 manager->fd_signal = safe_close(manager->fd_signal);
+                manager->fd_inotify = safe_close(manager->fd_inotify);
                 manager->worker_watch[READ_END] = safe_close(manager->worker_watch[READ_END]);
-                manager->fd_ep = safe_close(manager->fd_ep);
 
                 sigfillset(&mask);
                 fd_signal = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC);



More information about the systemd-commits mailing list