diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-11-27 10:34:32 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-11-28 05:08:19 +0100 |
commit | cb3108669d623afe58a36077e36ae4c66ff7d1c3 (patch) | |
tree | ca18128fa900fd2c2fcea59a30743cc1c1ba73a0 | |
parent | test: make TEST-27 non-racy (diff) | |
download | systemd-cb3108669d623afe58a36077e36ae4c66ff7d1c3.tar.xz systemd-cb3108669d623afe58a36077e36ae4c66ff7d1c3.zip |
tree-wide: more IOVEC_MAKE() conversions
-rw-r--r-- | coccinelle/iovec-make.cocci | 5 | ||||
-rw-r--r-- | src/libsystemd-network/sd-dhcp-client.c | 6 | ||||
-rw-r--r-- | src/libsystemd-network/sd-dhcp-server.c | 4 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-message.c | 3 | ||||
-rw-r--r-- | src/libsystemd/sd-daemon/sd-daemon.c | 7 | ||||
-rw-r--r-- | src/libsystemd/sd-device/device-monitor.c | 6 | ||||
-rw-r--r-- | src/libsystemd/sd-netlink/netlink-socket.c | 4 | ||||
-rw-r--r-- | src/libsystemd/sd-resolve/sd-resolve.c | 35 | ||||
-rw-r--r-- | src/machine/machine-dbus.c | 5 | ||||
-rw-r--r-- | src/resolve/resolved-manager.c | 22 |
10 files changed, 50 insertions, 47 deletions
diff --git a/coccinelle/iovec-make.cocci b/coccinelle/iovec-make.cocci index 62defe9400..7a0d4ced9b 100644 --- a/coccinelle/iovec-make.cocci +++ b/coccinelle/iovec-make.cocci @@ -22,3 +22,8 @@ expression s; @@ - IOVEC_MAKE(s, strlen(s)); + IOVEC_MAKE_STRING(s); +@@ +expression x, y, z; +@@ +- x = (struct iovec) { .iov_base = y, .iov_len = z }; ++ x = IOVEC_MAKE(y, z); diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c index df9428518f..842aeaa6b1 100644 --- a/src/libsystemd-network/sd-dhcp-client.c +++ b/src/libsystemd-network/sd-dhcp-client.c @@ -23,10 +23,11 @@ #include "dns-domain.h" #include "event-util.h" #include "hostname-util.h" +#include "io-util.h" #include "random-util.h" #include "string-util.h" -#include "util.h" #include "strv.h" +#include "util.h" #define MAX_CLIENT_ID_LEN (sizeof(uint32_t) + MAX_DUID_LEN) /* Arbitrary limit */ #define MAX_MAC_ADDR_LEN CONST_MAX(INFINIBAND_ALEN, ETH_ALEN) @@ -1784,8 +1785,7 @@ static int client_receive_message_raw( if (!packet) return -ENOMEM; - iov.iov_base = packet; - iov.iov_len = buflen; + iov = IOVEC_MAKE(packet, buflen); len = recvmsg(fd, &msg, 0); if (len < 0) { diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c index 2458d55628..2a68a02985 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -12,6 +12,7 @@ #include "dhcp-server-internal.h" #include "fd-util.h" #include "in-addr-util.h" +#include "io-util.h" #include "sd-id128.h" #include "siphash24.h" #include "string-util.h" @@ -943,8 +944,7 @@ static int server_receive_message(sd_event_source *s, int fd, if (!message) return -ENOMEM; - iov.iov_base = message; - iov.iov_len = buflen; + iov = IOVEC_MAKE(message, buflen); len = recvmsg(fd, &msg, 0); if (len < 0) { diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c index e80cfc882a..f25db35998 100644 --- a/src/libsystemd/sd-bus/bus-message.c +++ b/src/libsystemd/sd-bus/bus-message.c @@ -554,8 +554,7 @@ int bus_message_from_malloc( m->n_iovec = 1; m->iovec = m->iovec_fixed; - m->iovec[0].iov_base = buffer; - m->iovec[0].iov_len = length; + m->iovec[0] = IOVEC_MAKE(buffer, length); r = bus_message_parse_fields(m); if (r < 0) diff --git a/src/libsystemd/sd-daemon/sd-daemon.c b/src/libsystemd/sd-daemon/sd-daemon.c index 44c1d312e1..218210f234 100644 --- a/src/libsystemd/sd-daemon/sd-daemon.c +++ b/src/libsystemd/sd-daemon/sd-daemon.c @@ -19,6 +19,7 @@ #include "alloc-util.h" #include "fd-util.h" #include "fs-util.h" +#include "io-util.h" #include "parse-util.h" #include "path-util.h" #include "process-util.h" @@ -445,9 +446,7 @@ _public_ int sd_pid_notify_with_fds( unsigned n_fds) { union sockaddr_union sockaddr = {}; - struct iovec iovec = { - .iov_base = (char*) state, - }; + struct iovec iovec; struct msghdr msghdr = { .msg_iov = &iovec, .msg_iovlen = 1, @@ -487,7 +486,7 @@ _public_ int sd_pid_notify_with_fds( (void) fd_inc_sndbuf(fd, SNDBUF_SIZE); - iovec.iov_len = strlen(state); + iovec = IOVEC_MAKE_STRING(state); msghdr.msg_namelen = salen; send_ucred = diff --git a/src/libsystemd/sd-device/device-monitor.c b/src/libsystemd/sd-device/device-monitor.c index 8f2eec1bda..3ab3ce0dca 100644 --- a/src/libsystemd/sd-device/device-monitor.c +++ b/src/libsystemd/sd-device/device-monitor.c @@ -16,6 +16,7 @@ #include "fd-util.h" #include "format-util.h" #include "hashmap.h" +#include "io-util.h" #include "missing.h" #include "mount-util.h" #include "set.h" @@ -541,10 +542,7 @@ int device_monitor_send_device( /* add properties list */ nlh.properties_off = iov[0].iov_len; nlh.properties_len = blen; - iov[1] = (struct iovec) { - .iov_base = (char*) buf, - .iov_len = blen, - }; + iov[1] = IOVEC_MAKE((char*) buf, blen); /* * Use custom address for target, or the default one. diff --git a/src/libsystemd/sd-netlink/netlink-socket.c b/src/libsystemd/sd-netlink/netlink-socket.c index b1b9f6d8ce..432e8e8c06 100644 --- a/src/libsystemd/sd-netlink/netlink-socket.c +++ b/src/libsystemd/sd-netlink/netlink-socket.c @@ -9,6 +9,7 @@ #include "alloc-util.h" #include "fd-util.h" #include "format-util.h" +#include "io-util.h" #include "missing.h" #include "netlink-internal.h" #include "netlink-types.h" @@ -334,8 +335,7 @@ int socket_read_message(sd_netlink *rtnl) { len, sizeof(uint8_t))) return -ENOMEM; - iov.iov_base = rtnl->rbuffer; - iov.iov_len = rtnl->rbuffer_allocated; + iov = IOVEC_MAKE(rtnl->rbuffer, rtnl->rbuffer_allocated); /* read the pending message */ r = socket_recv_message(rtnl->fd, &iov, &group, false); diff --git a/src/libsystemd/sd-resolve/sd-resolve.c b/src/libsystemd/sd-resolve/sd-resolve.c index 1fbab9dbf9..e31b808c66 100644 --- a/src/libsystemd/sd-resolve/sd-resolve.c +++ b/src/libsystemd/sd-resolve/sd-resolve.c @@ -262,10 +262,13 @@ static int send_addrinfo_reply( if (ai) freeaddrinfo(ai); - iov[0] = (struct iovec) { .iov_base = &resp, .iov_len = sizeof(AddrInfoResponse) }; - iov[1] = (struct iovec) { .iov_base = &buffer, .iov_len = resp.header.length - sizeof(AddrInfoResponse) }; + iov[0] = IOVEC_MAKE(&resp, sizeof(AddrInfoResponse)); + iov[1] = IOVEC_MAKE(&buffer, resp.header.length - sizeof(AddrInfoResponse)); - mh = (struct msghdr) { .msg_iov = iov, .msg_iovlen = ELEMENTSOF(iov) }; + mh = (struct msghdr) { + .msg_iov = iov, + .msg_iovlen = ELEMENTSOF(iov) + }; if (sendmsg(out_fd, &mh, MSG_NOSIGNAL) < 0) return -errno; @@ -303,11 +306,14 @@ static int send_nameinfo_reply( ._h_errno = _h_errno, }; - iov[0] = (struct iovec) { .iov_base = &resp, .iov_len = sizeof(NameInfoResponse) }; - iov[1] = (struct iovec) { .iov_base = (void*) host, .iov_len = hl }; - iov[2] = (struct iovec) { .iov_base = (void*) serv, .iov_len = sl }; + iov[0] = IOVEC_MAKE(&resp, sizeof(NameInfoResponse)); + iov[1] = IOVEC_MAKE((void*) host, hl); + iov[2] = IOVEC_MAKE((void*) serv, sl); - mh = (struct msghdr) { .msg_iov = iov, .msg_iovlen = ELEMENTSOF(iov) }; + mh = (struct msghdr) { + .msg_iov = iov, + .msg_iovlen = ELEMENTSOF(iov) + }; if (sendmsg(out_fd, &mh, MSG_NOSIGNAL) < 0) return -errno; @@ -951,11 +957,11 @@ _public_ int sd_resolve_getaddrinfo( .ai_protocol = hints ? hints->ai_protocol : 0, }; - iov[mh.msg_iovlen++] = (struct iovec) { .iov_base = &req, .iov_len = sizeof(AddrInfoRequest) }; + iov[mh.msg_iovlen++] = IOVEC_MAKE(&req, sizeof(AddrInfoRequest)); if (node) - iov[mh.msg_iovlen++] = (struct iovec) { .iov_base = (void*) node, .iov_len = req.node_len }; + iov[mh.msg_iovlen++] = IOVEC_MAKE((void*) node, req.node_len); if (service) - iov[mh.msg_iovlen++] = (struct iovec) { .iov_base = (void*) service, .iov_len = req.service_len }; + iov[mh.msg_iovlen++] = IOVEC_MAKE((void*) service, req.service_len); mh.msg_iov = iov; if (sendmsg(resolve->fds[REQUEST_SEND_FD], &mh, MSG_NOSIGNAL) < 0) @@ -1023,10 +1029,13 @@ _public_ int sd_resolve_getnameinfo( .getserv = !!(get & SD_RESOLVE_GET_SERVICE), }; - iov[0] = (struct iovec) { .iov_base = &req, .iov_len = sizeof(NameInfoRequest) }; - iov[1] = (struct iovec) { .iov_base = (void*) sa, .iov_len = salen }; + iov[0] = IOVEC_MAKE(&req, sizeof(NameInfoRequest)); + iov[1] = IOVEC_MAKE((void*) sa, salen); - mh = (struct msghdr) { .msg_iov = iov, .msg_iovlen = ELEMENTSOF(iov) }; + mh = (struct msghdr) { + .msg_iov = iov, + .msg_iovlen = ELEMENTSOF(iov) + }; if (sendmsg(resolve->fds[REQUEST_SEND_FD], &mh, MSG_NOSIGNAL) < 0) return -errno; diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c index c921974cbe..da861c536c 100644 --- a/src/machine/machine-dbus.c +++ b/src/machine/machine-dbus.c @@ -23,6 +23,7 @@ #include "format-util.h" #include "fs-util.h" #include "in-addr-util.h" +#include "io-util.h" #include "local-addresses.h" #include "machine-dbus.h" #include "machine.h" @@ -250,8 +251,8 @@ int bus_machine_method_get_addresses(sd_bus_message *message, void *userdata, sd .msg_iovlen = 2, }; - iov[0] = (struct iovec) { .iov_base = &family, .iov_len = sizeof(family) }; - iov[1] = (struct iovec) { .iov_base = &in_addr, .iov_len = sizeof(in_addr) }; + iov[0] = IOVEC_MAKE(&family, sizeof(family)); + iov[1] = IOVEC_MAKE(&in_addr, sizeof(in_addr)); n = recvmsg(pair[0], &mh, 0); if (n < 0) diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index cbdeebb211..0fdc84d57a 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -17,6 +17,7 @@ #include "fileio-label.h" #include "hostname-util.h" #include "io-util.h" +#include "io-util.h" #include "netlink-util.h" #include "network-internal.h" #include "ordered-set.h" @@ -24,8 +25,8 @@ #include "random-util.h" #include "resolved-bus.h" #include "resolved-conf.h" -#include "resolved-dnssd.h" #include "resolved-dns-stub.h" +#include "resolved-dnssd.h" #include "resolved-etc-hosts.h" #include "resolved-llmnr.h" #include "resolved-manager.h" @@ -752,20 +753,17 @@ int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret) { if (r < 0) return r; - iov = (struct iovec) { - .iov_base = DNS_PACKET_DATA(p), - iov.iov_len = p->allocated, - }; + iov = IOVEC_MAKE(DNS_PACKET_DATA(p), p->allocated); l = recvmsg(fd, &mh, 0); - if (l == 0) - return 0; if (l < 0) { if (IN_SET(errno, EAGAIN, EINTR)) return 0; return -errno; } + if (l == 0) + return 0; assert(!(mh.msg_flags & MSG_CTRUNC)); assert(!(mh.msg_flags & MSG_TRUNC)); @@ -934,10 +932,7 @@ static int manager_ipv4_send( assert(port > 0); assert(p); - iov = (struct iovec) { - .iov_base = DNS_PACKET_DATA(p), - .iov_len = p->size, - }; + iov = IOVEC_MAKE(DNS_PACKET_DATA(p), p->size); sa = (union sockaddr_union) { .in.sin_family = AF_INET, @@ -995,10 +990,7 @@ static int manager_ipv6_send( assert(port > 0); assert(p); - iov = (struct iovec) { - .iov_base = DNS_PACKET_DATA(p), - .iov_len = p->size, - }; + iov = IOVEC_MAKE(DNS_PACKET_DATA(p), p->size); sa = (union sockaddr_union) { .in6.sin6_family = AF_INET6, |