tree-wide: use IOVEC_MAKE() at many places

This commit is contained in:
Lennart Poettering 2018-11-26 21:52:36 +01:00 committed by Zbigniew Jędrzejewski-Szmek
parent eaf6369769
commit 5cfa2c3dc0
14 changed files with 65 additions and 72 deletions

View File

@ -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);

View 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)++;
}

View 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++;

View 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) {

View 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);
}

View 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);

View 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

View 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)

View 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"
@ -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;

View 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);

View 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);

View 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)

View 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);

View 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) {