[systemd-commits] 2 commits - src/network src/shared src/udev TODO

Tom Gundersen tomegun at kemper.freedesktop.org
Mon May 11 15:44:26 PDT 2015


 TODO                           |    2 -
 src/network/networkd-network.c |   21 +++++++++-----------
 src/shared/udev-util.h         |    4 +++
 src/udev/udevd.c               |   42 ++++++++++++++++++++---------------------
 4 files changed, 35 insertions(+), 34 deletions(-)

New commits:
commit 24c083dfcbff3d1dd86a22cba7555a9ae6d8a53d
Author: Tom Gundersen <teg at jklm.no>
Date:   Tue May 12 00:22:29 2015 +0200

    networkd: network_get - allow udev_device to be NULL
    
    In containers we never have udev devices, so drop the assert.
    
    This fixes an assertion introduced in af3aa302741b6edb0729925febb5f8bc26721fe3.

diff --git a/TODO b/TODO
index 3edb7fd..932fef6 100644
--- a/TODO
+++ b/TODO
@@ -49,8 +49,6 @@ Before 220:
 
 * introduce argv0array=
 
-* Assertion 'device' failed at src/network/networkd-network.c:280, function network_get(). Aborting.
-
 Features:
 
 * invent a better systemd-run scheme for naming scopes, that works with remoting
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 4d4972e..8aa4eb2 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -273,23 +273,22 @@ int network_get(Manager *manager, struct udev_device *device,
                 Network **ret) {
         Network *network;
         struct udev_device *parent;
-        const char *path, *parent_driver, *driver, *devtype;
+        const char *path = NULL, *parent_driver = NULL, *driver = NULL, *devtype = NULL;
 
         assert(manager);
         assert(ret);
-        assert(device);
 
-        path = udev_device_get_property_value(device, "ID_PATH");
+        if (device) {
+                path = udev_device_get_property_value(device, "ID_PATH");
 
-        parent = udev_device_get_parent(device);
-        if (parent)
-                parent_driver = udev_device_get_driver(parent);
-        else
-                parent_driver = NULL;
+                parent = udev_device_get_parent(device);
+                if (parent)
+                        parent_driver = udev_device_get_driver(parent);
 
-        driver = udev_device_get_property_value(device, "ID_NET_DRIVER");
+                driver = udev_device_get_property_value(device, "ID_NET_DRIVER");
 
-        devtype = udev_device_get_devtype(device);
+                devtype = udev_device_get_devtype(device);
+        }
 
         LIST_FOREACH(networks, network, manager->networks) {
                 if (net_match_config(network->match_mac, network->match_path,
@@ -299,7 +298,7 @@ int network_get(Manager *manager, struct udev_device *device,
                                      network->match_arch,
                                      address, path, parent_driver, driver,
                                      devtype, ifname)) {
-                        if (network->match_name) {
+                        if (network->match_name && device) {
                                 const char *attr;
                                 uint8_t name_assign_type = NET_NAME_UNKNOWN;
 

commit e4f66b7773ae21278bf6b9c02a3282eec5996266
Author: Tom Gundersen <teg at jklm.no>
Date:   Mon May 11 22:17:49 2015 +0200

    udevd: make udev_ctrl_connection global
    
    This allows us to simplify the ctrl_msg handler. Eventually all this global state should move to
    a Manager object or so.

diff --git a/src/shared/udev-util.h b/src/shared/udev-util.h
index 5f09ce1..f758ce1 100644
--- a/src/shared/udev-util.h
+++ b/src/shared/udev-util.h
@@ -30,6 +30,8 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_enumerate*, udev_enumerate_unref);
 DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_event*, udev_event_unref);
 DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_rules*, udev_rules_unref);
 DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_ctrl*, udev_ctrl_unref);
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_ctrl_connection*, udev_ctrl_connection_unref);
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_ctrl_msg*, udev_ctrl_msg_unref);
 DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_monitor*, udev_monitor_unref);
 
 #define _cleanup_udev_unref_ _cleanup_(udev_unrefp)
@@ -38,5 +40,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_monitor*, udev_monitor_unref);
 #define _cleanup_udev_event_unref_ _cleanup_(udev_event_unrefp)
 #define _cleanup_udev_rules_unref_ _cleanup_(udev_rules_unrefp)
 #define _cleanup_udev_ctrl_unref_ _cleanup_(udev_ctrl_unrefp)
+#define _cleanup_udev_ctrl_connection_unref_ _cleanup_(udev_ctrl_connection_unrefp)
+#define _cleanup_udev_ctrl_msg_unref_ _cleanup_(udev_ctrl_msg_unrefp)
 #define _cleanup_udev_monitor_unref_ _cleanup_(udev_monitor_unrefp)
 #define _cleanup_udev_list_cleanup_ _cleanup_(udev_list_cleanup)
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index ff36aaf..27d8b12 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -53,6 +53,7 @@
 
 static struct udev_rules *rules;
 static struct udev_ctrl *udev_ctrl;
+static struct udev_ctrl_connection *udev_ctrl_conn;
 static struct udev_monitor *monitor;
 static int worker_watch[2] = { -1, -1 };
 static int fd_signal = -1;
@@ -500,7 +501,7 @@ static int event_queue_insert(struct udev_device *dev) {
         return 0;
 }
 
-static void worker_kill(struct udev *udev) {
+static void worker_kill(void) {
         struct worker *worker;
         Iterator i;
 
@@ -677,26 +678,27 @@ static void worker_returned(int fd_worker) {
 }
 
 /* receive the udevd message from userspace */
-static struct udev_ctrl_connection *handle_ctrl_msg(struct udev_ctrl *uctrl) {
-        struct udev *udev = udev_ctrl_get_udev(uctrl);
-        struct udev_ctrl_connection *ctrl_conn;
-        struct udev_ctrl_msg *ctrl_msg = NULL;
+static void handle_ctrl_msg(struct udev_ctrl *uctrl) {
+        _cleanup_udev_ctrl_connection_unref_ struct udev_ctrl_connection *ctrl_conn = NULL;
+        _cleanup_udev_ctrl_msg_unref_ struct udev_ctrl_msg *ctrl_msg = NULL;
         const char *str;
         int i;
 
+        assert(uctrl);
+
         ctrl_conn = udev_ctrl_get_connection(uctrl);
-        if (ctrl_conn == NULL)
-                goto out;
+        if (!ctrl_conn)
+                return;
 
         ctrl_msg = udev_ctrl_receive_msg(ctrl_conn);
-        if (ctrl_msg == NULL)
-                goto out;
+        if (!ctrl_msg)
+                return;
 
         i = udev_ctrl_get_set_log_level(ctrl_msg);
         if (i >= 0) {
                 log_debug("udevd message (SET_LOG_LEVEL) received, log_priority=%i", i);
                 log_set_max_level(i);
-                worker_kill(udev);
+                worker_kill();
         }
 
         if (udev_ctrl_get_stop_exec_queue(ctrl_msg) > 0) {
@@ -738,7 +740,7 @@ static struct udev_ctrl_connection *handle_ctrl_msg(struct udev_ctrl *uctrl) {
                         }
                         free(key);
                 }
-                worker_kill(udev);
+                worker_kill();
         }
 
         i = udev_ctrl_get_set_children_max(ctrl_msg);
@@ -754,11 +756,10 @@ static struct udev_ctrl_connection *handle_ctrl_msg(struct udev_ctrl *uctrl) {
                 log_debug("udevd message (EXIT) received");
                 udev_exit = true;
                 /* keep reference to block the client until we exit */
-                udev_ctrl_connection_ref(ctrl_conn);
+                udev_ctrl_conn = udev_ctrl_connection_ref(ctrl_conn);
         }
-out:
-        udev_ctrl_msg_unref(ctrl_msg);
-        return udev_ctrl_connection_unref(ctrl_conn);
+
+        return;
 }
 
 static int synthesize_change(struct udev_device *dev) {
@@ -1158,7 +1159,6 @@ int main(int argc, char *argv[]) {
         struct epoll_event ep_signal = { .events = EPOLLIN };
         struct epoll_event ep_netlink = { .events = EPOLLIN };
         struct epoll_event ep_worker = { .events = EPOLLIN };
-        struct udev_ctrl_connection *ctrl_conn = NULL;
         int r = 0, one = 1;
 
         udev = udev_new();
@@ -1397,7 +1397,7 @@ int main(int argc, char *argv[]) {
 
                         /* discard queued events and kill workers */
                         event_queue_cleanup(udev, EVENT_QUEUED);
-                        worker_kill(udev);
+                        worker_kill();
 
                         /* exit after all has cleaned up */
                         if (udev_list_node_is_empty(&event_list) && hashmap_isempty(workers))
@@ -1437,7 +1437,7 @@ int main(int argc, char *argv[]) {
                         /* kill idle workers */
                         if (udev_list_node_is_empty(&event_list)) {
                                 log_debug("cleanup idle workers");
-                                worker_kill(udev);
+                                worker_kill();
                         }
 
                         /* check for hanging events */
@@ -1494,7 +1494,7 @@ int main(int argc, char *argv[]) {
 
                 /* reload requested, HUP signal received, rules changed, builtin changed */
                 if (reload) {
-                        worker_kill(udev);
+                        worker_kill();
                         rules = udev_rules_unref(rules);
                         udev_builtin_exit(udev);
                         reload = false;
@@ -1569,7 +1569,7 @@ int main(int argc, char *argv[]) {
                  * exit.
                  */
                 if (is_ctrl)
-                        ctrl_conn = handle_ctrl_msg(udev_ctrl);
+                        handle_ctrl_msg(udev_ctrl);
         }
 
 exit:
@@ -1589,7 +1589,7 @@ exit_daemonize:
         if (worker_watch[WRITE_END] >= 0)
                 close(worker_watch[WRITE_END]);
         udev_monitor_unref(monitor);
-        udev_ctrl_connection_unref(ctrl_conn);
+        udev_ctrl_connection_unref(udev_ctrl_conn);
         udev_ctrl_unref(udev_ctrl);
         udev_list_cleanup(&properties_list);
         mac_selinux_finish();



More information about the systemd-commits mailing list