summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-11-26 21:52:36 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-11-27 10:12:27 +0100
commit5cfa2c3dc09ffed16e3ad249e893911e372d3ed0 (patch)
tree11a7f2aec6fba69fbdfdfdf51e189523d95ecc83
parentMerge pull request #10949 from yuwata/man-improve-unset (diff)
downloadsystemd-5cfa2c3dc09ffed16e3ad249e893911e372d3ed0.tar.xz
systemd-5cfa2c3dc09ffed16e3ad249e893911e372d3ed0.zip
tree-wide: use IOVEC_MAKE() at many places
-rw-r--r--coccinelle/iovec-make.cocci24
-rw-r--r--src/basic/log.c3
-rw-r--r--src/journal/journald-native.c3
-rw-r--r--src/journal/journald-server.c3
-rw-r--r--src/journal/test-journal-interleaving.c6
-rw-r--r--src/journal/test-journal-verify.c4
-rw-r--r--src/journal/test-journal.c13
-rw-r--r--src/libsystemd-network/icmp6-util.c6
-rw-r--r--src/libsystemd-network/sd-radv.c35
-rw-r--r--src/libsystemd/sd-bus/bus-socket.c22
-rw-r--r--src/resolve/resolved-dns-stream.c6
-rw-r--r--src/resolve/resolved-dnstls-openssl.c4
-rw-r--r--src/shared/ask-password-api.c4
-rw-r--r--src/udev/udev-ctrl.c4
14 files changed, 65 insertions, 72 deletions
diff --git a/coccinelle/iovec-make.cocci b/coccinelle/iovec-make.cocci
new file mode 100644
index 0000000000..62defe9400
--- /dev/null
+++ b/coccinelle/iovec-make.cocci
@@ -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);
diff --git a/src/basic/log.c b/src/basic/log.c
index 71e7031bc4..0486027296 100644
--- a/src/basic/log.c
+++ b/src/basic/log.c
@@ -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)++;
}
diff --git a/src/journal/journald-native.c b/src/journal/journald-native.c
index 5ea4601ba3..7a43599329 100644
--- a/src/journal/journald-native.c
+++ b/src/journal/journald-native.c
@@ -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++;
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index f7df39bd23..434325c179 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -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) {
diff --git a/src/journal/test-journal-interleaving.c b/src/journal/test-journal-interleaving.c
index 6d282e01fa..cf0561df61 100644
--- a/src/journal/test-journal-interleaving.c
+++ b/src/journal/test-journal-interleaving.c
@@ -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);
}
diff --git a/src/journal/test-journal-verify.c b/src/journal/test-journal-verify.c
index 8d6b441213..c4fa41e076 100644
--- a/src/journal/test-journal-verify.c
+++ b/src/journal/test-journal-verify.c
@@ -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);
diff --git a/src/journal/test-journal.c b/src/journal/test-journal.c
index 34f202c81d..0795e0da0a 100644
--- a/src/journal/test-journal.c
+++ b/src/journal/test-journal.c
@@ -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
diff --git a/src/libsystemd-network/icmp6-util.c b/src/libsystemd-network/icmp6-util.c
index ecb517f7ec..e535b12cda 100644
--- a/src/libsystemd-network/icmp6-util.c
+++ b/src/libsystemd-network/icmp6-util.c
@@ -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)
diff --git a/src/libsystemd-network/sd-radv.c b/src/libsystemd-network/sd-radv.c
index 4df7f273ce..fe458bcaa6 100644
--- a/src/libsystemd-network/sd-radv.c
+++ b/src/libsystemd-network/sd-radv.c
@@ -9,7 +9,6 @@
#include "sd-radv.h"
-#include "macro.h"
#include "alloc-util.h"
#include "dns-domain.h"
#include "ether-addr-util.h"
@@ -17,12 +16,14 @@
#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;
diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c
index a785a247c8..f7485211ac 100644
--- a/src/libsystemd/sd-bus/bus-socket.c
+++ b/src/libsystemd/sd-bus/bus-socket.c
@@ -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);
diff --git a/src/resolve/resolved-dns-stream.c b/src/resolve/resolved-dns-stream.c
index 9a5c7c34f3..26d4663d74 100644
--- a/src/resolve/resolved-dns-stream.c
+++ b/src/resolve/resolved-dns-stream.c
@@ -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);
diff --git a/src/resolve/resolved-dnstls-openssl.c b/src/resolve/resolved-dnstls-openssl.c
index 0ebaa660c5..bdd37a637f 100644
--- a/src/resolve/resolved-dnstls-openssl.c
+++ b/src/resolve/resolved-dnstls-openssl.c
@@ -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)
diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c
index 0cab1759b0..37441a8f5b 100644
--- a/src/shared/ask-password-api.c
+++ b/src/shared/ask-password-api.c
@@ -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);
diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c
index 6ea74c7bf7..f2238ae14e 100644
--- a/src/udev/udev-ctrl.c
+++ b/src/udev/udev-ctrl.c
@@ -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) {