]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: use IOVEC_MAKE() at many places
authorLennart Poettering <lennart@poettering.net>
Mon, 26 Nov 2018 20:52:36 +0000 (21:52 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 27 Nov 2018 09:12:27 +0000 (10:12 +0100)
14 files changed:
coccinelle/iovec-make.cocci [new file with mode: 0644]
src/basic/log.c
src/journal/journald-native.c
src/journal/journald-server.c
src/journal/test-journal-interleaving.c
src/journal/test-journal-verify.c
src/journal/test-journal.c
src/libsystemd-network/icmp6-util.c
src/libsystemd-network/sd-radv.c
src/libsystemd/sd-bus/bus-socket.c
src/resolve/resolved-dns-stream.c
src/resolve/resolved-dnstls-openssl.c
src/shared/ask-password-api.c
src/udev/udev-ctrl.c

diff --git a/coccinelle/iovec-make.cocci b/coccinelle/iovec-make.cocci
new file mode 100644 (file)
index 0000000..62defe9
--- /dev/null
@@ -0,0 +1,24 @@
+@@
+expression x, y, p, l;
+@@
+- x[y].iov_base = p;
+- x[y].iov_len = l;
+- y++;
++ x[y++] = IOVEC_MAKE(p, l);
+@@
+expression x, p, l;
+@@
+- x.iov_base = p;
+- x.iov_len = l;
++ x = IOVEC_MAKE(p, l);
+@@
+expression x, p, l;
+@@
+- x->iov_base = p;
+- x->iov_len = l;
++ *x = IOVEC_MAKE(p, l);
+@@
+expression s;
+@@
+- IOVEC_MAKE(s, strlen(s));
++ IOVEC_MAKE_STRING(s);
index 71e7031bc40b6552a8781f984715096e06e55fab..0486027296d1cf777e2f0409add83ec8acb0c08f 100644 (file)
@@ -858,8 +858,7 @@ int log_format_iovec(
                 iovec[(*n)++] = IOVEC_MAKE_STRING(m);
 
                 if (newline_separator) {
-                        iovec[*n].iov_base = (char*) &nl;
-                        iovec[*n].iov_len = 1;
+                        iovec[*n] = IOVEC_MAKE((char *)&nl, 1);
                         (*n)++;
                 }
 
index 5ea4601ba35fdf29f78283608435630bae9e7b98..7a43599329ec0bfc8aed9204b931139fa07fb83d 100644 (file)
@@ -206,8 +206,7 @@ static int server_process_entry(
                         memcpy(k + (e - p) + 1, e + 1 + sizeof(uint64_t), l);
 
                         if (journal_field_valid(p, e - p, false)) {
-                                iovec[n].iov_base = k;
-                                iovec[n].iov_len = (e - p) + 1 + l;
+                                iovec[n] = IOVEC_MAKE(k, (e - p) + 1 + l);
                                 entry_size += iovec[n].iov_len;
                                 n++;
 
index f7df39bd23196a50252990d1be8d62be00529802..434325c1795ea5a95c59b0ec5b0b1aa412a043bf 100644 (file)
@@ -1266,8 +1266,7 @@ int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void
         if (!GREEDY_REALLOC(s->buffer, s->buffer_size, m))
                 return log_oom();
 
-        iovec.iov_base = s->buffer;
-        iovec.iov_len = s->buffer_size - 1; /* Leave room for trailing NUL we add later */
+        iovec = IOVEC_MAKE(s->buffer, s->buffer_size - 1); /* Leave room for trailing NUL we add later */
 
         n = recvmsg(fd, &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC);
         if (n < 0) {
index 6d282e01fa5645a87729dda160e6b5bf0d39ae79..cf0561df619f55420460fc44ec1e52469b16eac2 100644 (file)
@@ -6,13 +6,14 @@
 #include "sd-journal.h"
 
 #include "alloc-util.h"
+#include "io-util.h"
 #include "journal-file.h"
 #include "journal-vacuum.h"
 #include "log.h"
 #include "parse-util.h"
 #include "rm-rf.h"
-#include "util.h"
 #include "tests.h"
+#include "util.h"
 
 /* This program tests skipping around in a multi-file journal. */
 
@@ -58,8 +59,7 @@ static void append_number(JournalFile *f, int n, uint64_t *seqnum) {
         previous_ts = ts;
 
         assert_se(asprintf(&p, "NUMBER=%d", n) >= 0);
-        iovec[0].iov_base = p;
-        iovec[0].iov_len = strlen(p);
+        iovec[0] = IOVEC_MAKE_STRING(p);
         assert_ret(journal_file_append_entry(f, &ts, NULL, iovec, 1, seqnum, NULL, NULL));
         free(p);
 }
index 8d6b4412134402fec1a111462f07c87bd655f7f6..c4fa41e07682360fc877b7c4fcaa03c712639dcd 100644 (file)
@@ -5,6 +5,7 @@
 #include <unistd.h>
 
 #include "fd-util.h"
+#include "io-util.h"
 #include "journal-file.h"
 #include "journal-verify.h"
 #include "log.h"
@@ -83,8 +84,7 @@ int main(int argc, char *argv[]) {
 
                 assert_se(asprintf(&test, "RANDOM=%lu", random() % RANDOM_RANGE));
 
-                iovec.iov_base = (void*) test;
-                iovec.iov_len = strlen(test);
+                iovec = IOVEC_MAKE_STRING(test);
 
                 assert_se(journal_file_append_entry(f, &ts, NULL, &iovec, 1, NULL, NULL, NULL) == 0);
 
index 34f202c81da244382eb6d644504b68c516831522..0795e0da0a82503b19f7f81eb3dc500c59c54c0d 100644 (file)
@@ -3,6 +3,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 
+#include "io-util.h"
 #include "journal-authenticate.h"
 #include "journal-file.h"
 #include "journal-vacuum.h"
@@ -32,16 +33,13 @@ static void test_non_empty(void) {
         assert_se(dual_timestamp_get(&ts));
         assert_se(sd_id128_randomize(&fake_boot_id) == 0);
 
-        iovec.iov_base = (void*) test;
-        iovec.iov_len = strlen(test);
+        iovec = IOVEC_MAKE_STRING(test);
         assert_se(journal_file_append_entry(f, &ts, NULL, &iovec, 1, NULL, NULL, NULL) == 0);
 
-        iovec.iov_base = (void*) test2;
-        iovec.iov_len = strlen(test2);
+        iovec = IOVEC_MAKE_STRING(test2);
         assert_se(journal_file_append_entry(f, &ts, NULL, &iovec, 1, NULL, NULL, NULL) == 0);
 
-        iovec.iov_base = (void*) test;
-        iovec.iov_len = strlen(test);
+        iovec = IOVEC_MAKE_STRING(test);
         assert_se(journal_file_append_entry(f, &ts, &fake_boot_id, &iovec, 1, NULL, NULL, NULL) == 0);
 
 #if HAVE_GCRYPT
@@ -174,8 +172,7 @@ static bool check_compressed(uint64_t compress_threshold, uint64_t data_size) {
 
         dual_timestamp_get(&ts);
 
-        iovec.iov_base = (void*) data;
-        iovec.iov_len = data_size;
+        iovec = IOVEC_MAKE(data, data_size);
         assert_se(journal_file_append_entry(f, &ts, NULL, &iovec, 1, NULL, NULL, NULL) == 0);
 
 #if HAVE_GCRYPT
index ecb517f7ec860b276b2270a20de46902c340a891..e535b12cda16d8027eb0ac470ef3f6918f9a9f2c 100644 (file)
@@ -17,8 +17,9 @@
 
 #include "fd-util.h"
 #include "icmp6-util.h"
-#include "socket-util.h"
 #include "in-addr-util.h"
+#include "io-util.h"
+#include "socket-util.h"
 
 #define IN6ADDR_ALL_ROUTERS_MULTICAST_INIT \
         { { { 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
@@ -169,8 +170,7 @@ int icmp6_receive(int fd, void *buffer, size_t size, struct in6_addr *dst,
         struct cmsghdr *cmsg;
         ssize_t len;
 
-        iov.iov_base = buffer;
-        iov.iov_len = size;
+        iov = IOVEC_MAKE(buffer, size);
 
         len = recvmsg(fd, &msg, MSG_DONTWAIT);
         if (len < 0)
index 4df7f273ce7c8a3547357d64479fff1c067d867d..fe458bcaa625d3dfd086054ea518324aff804888 100644 (file)
@@ -9,7 +9,6 @@
 
 #include "sd-radv.h"
 
-#include "macro.h"
 #include "alloc-util.h"
 #include "dns-domain.h"
 #include "ether-addr-util.h"
 #include "fd-util.h"
 #include "icmp6-util.h"
 #include "in-addr-util.h"
+#include "io-util.h"
+#include "macro.h"
 #include "radv-internal.h"
+#include "random-util.h"
 #include "socket-util.h"
 #include "string-util.h"
 #include "strv.h"
 #include "util.h"
-#include "random-util.h"
 
 _public_ int sd_radv_new(sd_radv **ret) {
         _cleanup_(sd_radv_unrefp) sd_radv *ra = NULL;
@@ -159,24 +160,18 @@ static int radv_send(sd_radv *ra, const struct in6_addr *dst, uint32_t router_li
         adv.nd_ra_curhoplimit = ra->hop_limit;
         adv.nd_ra_flags_reserved = ra->flags;
         adv.nd_ra_router_lifetime = htobe16(router_lifetime);
-        iov[msg.msg_iovlen].iov_base = &adv;
-        iov[msg.msg_iovlen].iov_len = sizeof(adv);
-        msg.msg_iovlen++;
+        iov[msg.msg_iovlen++] = IOVEC_MAKE(&adv, sizeof(adv));
 
         /* MAC address is optional, either because the link does not use L2
            addresses or load sharing is desired. See RFC 4861, Section 4.2 */
         if (!ether_addr_is_null(&ra->mac_addr)) {
                 opt_mac.slladdr = ra->mac_addr;
-                iov[msg.msg_iovlen].iov_base = &opt_mac;
-                iov[msg.msg_iovlen].iov_len = sizeof(opt_mac);
-                msg.msg_iovlen++;
+                iov[msg.msg_iovlen++] = IOVEC_MAKE(&opt_mac, sizeof(opt_mac));
         }
 
         if (ra->mtu) {
                 opt_mtu.nd_opt_mtu_mtu = htobe32(ra->mtu);
-                iov[msg.msg_iovlen].iov_base = &opt_mtu;
-                iov[msg.msg_iovlen].iov_len = sizeof(opt_mtu);
-                msg.msg_iovlen++;
+                iov[msg.msg_iovlen++] = IOVEC_MAKE(&opt_mtu, sizeof(opt_mtu));
         }
 
         LIST_FOREACH(prefix, p, ra->prefixes) {
@@ -192,22 +187,14 @@ static int radv_send(sd_radv *ra, const struct in6_addr *dst, uint32_t router_li
                         else
                                 p->opt.preferred_lifetime = htobe32((p->preferred_until - time_now) / USEC_PER_SEC);
                 }
-                iov[msg.msg_iovlen].iov_base = &p->opt;
-                iov[msg.msg_iovlen].iov_len = sizeof(p->opt);
-                msg.msg_iovlen++;
+                iov[msg.msg_iovlen++] = IOVEC_MAKE(&p->opt, sizeof(p->opt));
         }
 
-        if (ra->rdnss) {
-                iov[msg.msg_iovlen].iov_base = ra->rdnss;
-                iov[msg.msg_iovlen].iov_len = ra->rdnss->length * 8;
-                msg.msg_iovlen++;
-        }
+        if (ra->rdnss)
+                iov[msg.msg_iovlen++] = IOVEC_MAKE(ra->rdnss, ra->rdnss->length * 8);
 
-        if (ra->dnssl) {
-                iov[msg.msg_iovlen].iov_base = ra->dnssl;
-                iov[msg.msg_iovlen].iov_len = ra->dnssl->length * 8;
-                msg.msg_iovlen++;
-        }
+        if (ra->dnssl)
+                iov[msg.msg_iovlen++] = IOVEC_MAKE(ra->dnssl, ra->dnssl->length * 8);
 
         if (sendmsg(ra->fd, &msg, 0) < 0)
                 return -errno;
index a785a247c8720843ef8745fa60427734d343f8fd..f7485211ac60ec15c6eedef4c1dba6246fe75424 100644 (file)
@@ -44,8 +44,7 @@ static void iovec_advance(struct iovec iov[], unsigned *idx, size_t size) {
 
                 size -= i->iov_len;
 
-                i->iov_base = NULL;
-                i->iov_len = 0;
+                *i = IOVEC_MAKE(NULL, 0);
 
                 (*idx)++;
         }
@@ -56,9 +55,7 @@ static int append_iovec(sd_bus_message *m, const void *p, size_t sz) {
         assert(p);
         assert(sz > 0);
 
-        m->iovec[m->n_iovec].iov_base = (void*) p;
-        m->iovec[m->n_iovec].iov_len = sz;
-        m->n_iovec++;
+        m->iovec[m->n_iovec++] = IOVEC_MAKE((void*) p, sz);
 
         return 0;
 }
@@ -516,8 +513,7 @@ static int bus_socket_read_auth(sd_bus *b) {
 
         b->rbuffer = p;
 
-        iov.iov_base = (uint8_t*) b->rbuffer + b->rbuffer_size;
-        iov.iov_len = n - b->rbuffer_size;
+        iov = IOVEC_MAKE((uint8_t *)b->rbuffer + b->rbuffer_size, n - b->rbuffer_size);
 
         if (b->prefer_readv)
                 k = readv(b->input_fd, &iov, 1);
@@ -634,12 +630,9 @@ static int bus_socket_start_auth_client(sd_bus *b) {
         else
                 auth_suffix = "\r\nBEGIN\r\n";
 
-        b->auth_iovec[0].iov_base = (void*) auth_prefix;
-        b->auth_iovec[0].iov_len = 1 + strlen(auth_prefix + 1);
-        b->auth_iovec[1].iov_base = (void*) b->auth_buffer;
-        b->auth_iovec[1].iov_len = l * 2;
-        b->auth_iovec[2].iov_base = (void*) auth_suffix;
-        b->auth_iovec[2].iov_len = strlen(auth_suffix);
+        b->auth_iovec[0] = IOVEC_MAKE((void*) auth_prefix, 1 + strlen(auth_prefix + 1));
+        b->auth_iovec[1] = IOVEC_MAKE(b->auth_buffer, l * 2);
+        b->auth_iovec[2] = IOVEC_MAKE_STRING(auth_suffix);
 
         return bus_socket_write_auth(b);
 }
@@ -1146,8 +1139,7 @@ int bus_socket_read_message(sd_bus *bus) {
 
         bus->rbuffer = b;
 
-        iov.iov_base = (uint8_t*) bus->rbuffer + bus->rbuffer_size;
-        iov.iov_len = need - bus->rbuffer_size;
+        iov = IOVEC_MAKE((uint8_t *)bus->rbuffer + bus->rbuffer_size, need - bus->rbuffer_size);
 
         if (bus->prefer_readv)
                 k = readv(bus->input_fd, &iov, 1);
index 9a5c7c34f34622230ef3e4f0066e84574ab9b40f..26d4663d746f38999575346e897899543cd6de7f 100644 (file)
@@ -310,10 +310,8 @@ static int on_stream_io(sd_event_source *es, int fd, uint32_t revents, void *use
                 struct iovec iov[2];
                 ssize_t ss;
 
-                iov[0].iov_base = &s->write_size;
-                iov[0].iov_len = sizeof(s->write_size);
-                iov[1].iov_base = DNS_PACKET_DATA(s->write_packet);
-                iov[1].iov_len = s->write_packet->size;
+                iov[0] = IOVEC_MAKE(&s->write_size, sizeof(s->write_size));
+                iov[1] = IOVEC_MAKE(DNS_PACKET_DATA(s->write_packet), s->write_packet->size);
 
                 IOVEC_INCREMENT(iov, 2, s->n_written);
 
index 0ebaa660c59cd8c2067be13992be32b5c74c1260..bdd37a637f28bb5f31723e8e7ccfa9b00679bc95 100644 (file)
@@ -23,8 +23,8 @@ static int dnstls_flush_write_buffer(DnsStream *stream) {
                 assert(stream->dnstls_data.write_buffer->data);
 
                 struct iovec iov[1];
-                iov[0].iov_base = stream->dnstls_data.write_buffer->data;
-                iov[0].iov_len = stream->dnstls_data.write_buffer->length;
+                iov[0] = IOVEC_MAKE(stream->dnstls_data.write_buffer->data,
+                                    stream->dnstls_data.write_buffer->length);
                 ss = dns_stream_writev(stream, iov, 1, DNS_STREAM_WRITE_TLS_DATA);
                 if (ss < 0) {
                         if (ss == -EAGAIN)
index 0cab1759b0d2e4f1e6c5dcfe298e0358a2f594c6..37441a8f5b0883972a08a2d32f55e34ac1d7d129 100644 (file)
@@ -698,9 +698,7 @@ int ask_password_agent(
                         goto finish;
                 }
 
-                zero(iovec);
-                iovec.iov_base = passphrase;
-                iovec.iov_len = sizeof(passphrase);
+                iovec = IOVEC_MAKE(passphrase, sizeof(passphrase));
 
                 zero(control);
                 zero(msghdr);
index 6ea74c7bf70e66bc9d229185d5739433718f1313..f2238ae14edd8e6686dd79ddb423956c58f5f266 100644 (file)
@@ -20,6 +20,7 @@
 #include "alloc-util.h"
 #include "fd-util.h"
 #include "format-util.h"
+#include "io-util.h"
 #include "socket-util.h"
 #include "strxcpyx.h"
 #include "udev-ctrl.h"
@@ -344,8 +345,7 @@ struct udev_ctrl_msg *udev_ctrl_receive_msg(struct udev_ctrl_connection *conn) {
                 break;
         }
 
-        iov.iov_base = &uctrl_msg->ctrl_msg_wire;
-        iov.iov_len = sizeof(struct udev_ctrl_msg_wire);
+        iov = IOVEC_MAKE(&uctrl_msg->ctrl_msg_wire, sizeof(struct udev_ctrl_msg_wire));
 
         size = recvmsg(conn->sock, &smsg, 0);
         if (size < 0) {