From: Yu Watanabe Date: Wed, 3 Oct 2018 18:21:52 +0000 (+0900) Subject: sd-netlink: use structured initializers X-Git-Tag: v240~571^2~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2fea60901da26ac354cde806d8ef8fb5170eec26;p=thirdparty%2Fsystemd.git sd-netlink: use structured initializers --- diff --git a/src/libsystemd/sd-netlink/sd-netlink.c b/src/libsystemd/sd-netlink/sd-netlink.c index 678f36c377b..da5c0b0c3dd 100644 --- a/src/libsystemd/sd-netlink/sd-netlink.c +++ b/src/libsystemd/sd-netlink/sd-netlink.c @@ -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: