]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-netlink: use structured initializers
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 3 Oct 2018 18:21:52 +0000 (03:21 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 10 Oct 2018 05:43:05 +0000 (14:43 +0900)
src/libsystemd/sd-netlink/sd-netlink.c

index 678f36c377b7b8ceb54f46eca308138e14f89bff..da5c0b0c3ddd451857153c8cd69471603dcd07e4 100644 (file)
@@ -21,17 +21,23 @@ static int sd_netlink_new(sd_netlink **ret) {
 
         assert_return(ret, -EINVAL);
 
-        rtnl = new0(sd_netlink, 1);
+        rtnl = new(sd_netlink, 1);
         if (!rtnl)
                 return -ENOMEM;
 
-        rtnl->n_ref = REFCNT_INIT;
-        rtnl->fd = -1;
-        rtnl->sockaddr.nl.nl_family = AF_NETLINK;
-        rtnl->original_pid = getpid_cached();
-        rtnl->protocol = -1;
+        *rtnl = (sd_netlink) {
+                .n_ref = REFCNT_INIT,
+                .fd = -1,
+                .sockaddr.nl.nl_family = AF_NETLINK,
+                .original_pid = getpid_cached(),
+                .protocol = -1,
 
-        LIST_HEAD_INIT(rtnl->match_callbacks);
+                /* Change notification responses have sequence 0, so we must
+                 * start our request sequence numbers at 1, or we may confuse our
+                 * responses with notifications from the kernel */
+                .serial = 1,
+
+        };
 
         /* We guarantee that the read buffer has at least space for
          * a message header */
@@ -39,11 +45,6 @@ static int sd_netlink_new(sd_netlink **ret) {
                             sizeof(struct nlmsghdr), sizeof(uint8_t)))
                 return -ENOMEM;
 
-        /* Change notification responses have sequence 0, so we must
-         * start our request sequence numbers at 1, or we may confuse our
-         * responses with notifications from the kernel */
-        rtnl->serial = 1;
-
         *ret = TAKE_PTR(rtnl);
 
         return 0;
@@ -827,13 +828,15 @@ int sd_netlink_add_match(sd_netlink *rtnl,
         assert_return(callback, -EINVAL);
         assert_return(!rtnl_pid_changed(rtnl), -ECHILD);
 
-        c = new0(struct match_callback, 1);
+        c = new(struct match_callback, 1);
         if (!c)
                 return -ENOMEM;
 
-        c->callback = callback;
-        c->type = type;
-        c->userdata = userdata;
+        *c = (struct match_callback) {
+                .callback = callback,
+                .type = type,
+                .userdata = userdata,
+        };
 
         switch (type) {
                 case RTM_NEWLINK: