Skip to content

Commit 5cfa2c3

Browse files
poetteringkeszybz
authored andcommitted
tree-wide: use IOVEC_MAKE() at many places
1 parent eaf6369 commit 5cfa2c3

File tree

14 files changed

+65
-72
lines changed

14 files changed

+65
-72
lines changed

coccinelle/iovec-make.cocci

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@@
2+
expression x, y, p, l;
3+
@@
4+
- x[y].iov_base = p;
5+
- x[y].iov_len = l;
6+
- y++;
7+
+ x[y++] = IOVEC_MAKE(p, l);
8+
@@
9+
expression x, p, l;
10+
@@
11+
- x.iov_base = p;
12+
- x.iov_len = l;
13+
+ x = IOVEC_MAKE(p, l);
14+
@@
15+
expression x, p, l;
16+
@@
17+
- x->iov_base = p;
18+
- x->iov_len = l;
19+
+ *x = IOVEC_MAKE(p, l);
20+
@@
21+
expression s;
22+
@@
23+
- IOVEC_MAKE(s, strlen(s));
24+
+ IOVEC_MAKE_STRING(s);

src/basic/log.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,8 +858,7 @@ int log_format_iovec(
858858
iovec[(*n)++] = IOVEC_MAKE_STRING(m);
859859

860860
if (newline_separator) {
861-
iovec[*n].iov_base = (char*) &nl;
862-
iovec[*n].iov_len = 1;
861+
iovec[*n] = IOVEC_MAKE((char *)&nl, 1);
863862
(*n)++;
864863
}
865864

src/journal/journald-native.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ static int server_process_entry(
206206
memcpy(k + (e - p) + 1, e + 1 + sizeof(uint64_t), l);
207207

208208
if (journal_field_valid(p, e - p, false)) {
209-
iovec[n].iov_base = k;
210-
iovec[n].iov_len = (e - p) + 1 + l;
209+
iovec[n] = IOVEC_MAKE(k, (e - p) + 1 + l);
211210
entry_size += iovec[n].iov_len;
212211
n++;
213212

src/journal/journald-server.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,8 +1266,7 @@ int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void
12661266
if (!GREEDY_REALLOC(s->buffer, s->buffer_size, m))
12671267
return log_oom();
12681268

1269-
iovec.iov_base = s->buffer;
1270-
iovec.iov_len = s->buffer_size - 1; /* Leave room for trailing NUL we add later */
1269+
iovec = IOVEC_MAKE(s->buffer, s->buffer_size - 1); /* Leave room for trailing NUL we add later */
12711270

12721271
n = recvmsg(fd, &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC);
12731272
if (n < 0) {

src/journal/test-journal-interleaving.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
#include "sd-journal.h"
77

88
#include "alloc-util.h"
9+
#include "io-util.h"
910
#include "journal-file.h"
1011
#include "journal-vacuum.h"
1112
#include "log.h"
1213
#include "parse-util.h"
1314
#include "rm-rf.h"
14-
#include "util.h"
1515
#include "tests.h"
16+
#include "util.h"
1617

1718
/* This program tests skipping around in a multi-file journal. */
1819

@@ -58,8 +59,7 @@ static void append_number(JournalFile *f, int n, uint64_t *seqnum) {
5859
previous_ts = ts;
5960

6061
assert_se(asprintf(&p, "NUMBER=%d", n) >= 0);
61-
iovec[0].iov_base = p;
62-
iovec[0].iov_len = strlen(p);
62+
iovec[0] = IOVEC_MAKE_STRING(p);
6363
assert_ret(journal_file_append_entry(f, &ts, NULL, iovec, 1, seqnum, NULL, NULL));
6464
free(p);
6565
}

src/journal/test-journal-verify.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <unistd.h>
66

77
#include "fd-util.h"
8+
#include "io-util.h"
89
#include "journal-file.h"
910
#include "journal-verify.h"
1011
#include "log.h"
@@ -83,8 +84,7 @@ int main(int argc, char *argv[]) {
8384

8485
assert_se(asprintf(&test, "RANDOM=%lu", random() % RANDOM_RANGE));
8586

86-
iovec.iov_base = (void*) test;
87-
iovec.iov_len = strlen(test);
87+
iovec = IOVEC_MAKE_STRING(test);
8888

8989
assert_se(journal_file_append_entry(f, &ts, NULL, &iovec, 1, NULL, NULL, NULL) == 0);
9090

src/journal/test-journal.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <fcntl.h>
44
#include <unistd.h>
55

6+
#include "io-util.h"
67
#include "journal-authenticate.h"
78
#include "journal-file.h"
89
#include "journal-vacuum.h"
@@ -32,16 +33,13 @@ static void test_non_empty(void) {
3233
assert_se(dual_timestamp_get(&ts));
3334
assert_se(sd_id128_randomize(&fake_boot_id) == 0);
3435

35-
iovec.iov_base = (void*) test;
36-
iovec.iov_len = strlen(test);
36+
iovec = IOVEC_MAKE_STRING(test);
3737
assert_se(journal_file_append_entry(f, &ts, NULL, &iovec, 1, NULL, NULL, NULL) == 0);
3838

39-
iovec.iov_base = (void*) test2;
40-
iovec.iov_len = strlen(test2);
39+
iovec = IOVEC_MAKE_STRING(test2);
4140
assert_se(journal_file_append_entry(f, &ts, NULL, &iovec, 1, NULL, NULL, NULL) == 0);
4241

43-
iovec.iov_base = (void*) test;
44-
iovec.iov_len = strlen(test);
42+
iovec = IOVEC_MAKE_STRING(test);
4543
assert_se(journal_file_append_entry(f, &ts, &fake_boot_id, &iovec, 1, NULL, NULL, NULL) == 0);
4644

4745
#if HAVE_GCRYPT
@@ -174,8 +172,7 @@ static bool check_compressed(uint64_t compress_threshold, uint64_t data_size) {
174172

175173
dual_timestamp_get(&ts);
176174

177-
iovec.iov_base = (void*) data;
178-
iovec.iov_len = data_size;
175+
iovec = IOVEC_MAKE(data, data_size);
179176
assert_se(journal_file_append_entry(f, &ts, NULL, &iovec, 1, NULL, NULL, NULL) == 0);
180177

181178
#if HAVE_GCRYPT

src/libsystemd-network/icmp6-util.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717

1818
#include "fd-util.h"
1919
#include "icmp6-util.h"
20-
#include "socket-util.h"
2120
#include "in-addr-util.h"
21+
#include "io-util.h"
22+
#include "socket-util.h"
2223

2324
#define IN6ADDR_ALL_ROUTERS_MULTICAST_INIT \
2425
{ { { 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,
169170
struct cmsghdr *cmsg;
170171
ssize_t len;
171172

172-
iov.iov_base = buffer;
173-
iov.iov_len = size;
173+
iov = IOVEC_MAKE(buffer, size);
174174

175175
len = recvmsg(fd, &msg, MSG_DONTWAIT);
176176
if (len < 0)

src/libsystemd-network/sd-radv.c

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@
99

1010
#include "sd-radv.h"
1111

12-
#include "macro.h"
1312
#include "alloc-util.h"
1413
#include "dns-domain.h"
1514
#include "ether-addr-util.h"
1615
#include "event-util.h"
1716
#include "fd-util.h"
1817
#include "icmp6-util.h"
1918
#include "in-addr-util.h"
19+
#include "io-util.h"
20+
#include "macro.h"
2021
#include "radv-internal.h"
22+
#include "random-util.h"
2123
#include "socket-util.h"
2224
#include "string-util.h"
2325
#include "strv.h"
2426
#include "util.h"
25-
#include "random-util.h"
2627

2728
_public_ int sd_radv_new(sd_radv **ret) {
2829
_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
159160
adv.nd_ra_curhoplimit = ra->hop_limit;
160161
adv.nd_ra_flags_reserved = ra->flags;
161162
adv.nd_ra_router_lifetime = htobe16(router_lifetime);
162-
iov[msg.msg_iovlen].iov_base = &adv;
163-
iov[msg.msg_iovlen].iov_len = sizeof(adv);
164-
msg.msg_iovlen++;
163+
iov[msg.msg_iovlen++] = IOVEC_MAKE(&adv, sizeof(adv));
165164

166165
/* MAC address is optional, either because the link does not use L2
167166
addresses or load sharing is desired. See RFC 4861, Section 4.2 */
168167
if (!ether_addr_is_null(&ra->mac_addr)) {
169168
opt_mac.slladdr = ra->mac_addr;
170-
iov[msg.msg_iovlen].iov_base = &opt_mac;
171-
iov[msg.msg_iovlen].iov_len = sizeof(opt_mac);
172-
msg.msg_iovlen++;
169+
iov[msg.msg_iovlen++] = IOVEC_MAKE(&opt_mac, sizeof(opt_mac));
173170
}
174171

175172
if (ra->mtu) {
176173
opt_mtu.nd_opt_mtu_mtu = htobe32(ra->mtu);
177-
iov[msg.msg_iovlen].iov_base = &opt_mtu;
178-
iov[msg.msg_iovlen].iov_len = sizeof(opt_mtu);
179-
msg.msg_iovlen++;
174+
iov[msg.msg_iovlen++] = IOVEC_MAKE(&opt_mtu, sizeof(opt_mtu));
180175
}
181176

182177
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
192187
else
193188
p->opt.preferred_lifetime = htobe32((p->preferred_until - time_now) / USEC_PER_SEC);
194189
}
195-
iov[msg.msg_iovlen].iov_base = &p->opt;
196-
iov[msg.msg_iovlen].iov_len = sizeof(p->opt);
197-
msg.msg_iovlen++;
190+
iov[msg.msg_iovlen++] = IOVEC_MAKE(&p->opt, sizeof(p->opt));
198191
}
199192

200-
if (ra->rdnss) {
201-
iov[msg.msg_iovlen].iov_base = ra->rdnss;
202-
iov[msg.msg_iovlen].iov_len = ra->rdnss->length * 8;
203-
msg.msg_iovlen++;
204-
}
193+
if (ra->rdnss)
194+
iov[msg.msg_iovlen++] = IOVEC_MAKE(ra->rdnss, ra->rdnss->length * 8);
205195

206-
if (ra->dnssl) {
207-
iov[msg.msg_iovlen].iov_base = ra->dnssl;
208-
iov[msg.msg_iovlen].iov_len = ra->dnssl->length * 8;
209-
msg.msg_iovlen++;
210-
}
196+
if (ra->dnssl)
197+
iov[msg.msg_iovlen++] = IOVEC_MAKE(ra->dnssl, ra->dnssl->length * 8);
211198

212199
if (sendmsg(ra->fd, &msg, 0) < 0)
213200
return -errno;

src/libsystemd/sd-bus/bus-socket.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ static void iovec_advance(struct iovec iov[], unsigned *idx, size_t size) {
4444

4545
size -= i->iov_len;
4646

47-
i->iov_base = NULL;
48-
i->iov_len = 0;
47+
*i = IOVEC_MAKE(NULL, 0);
4948

5049
(*idx)++;
5150
}
@@ -56,9 +55,7 @@ static int append_iovec(sd_bus_message *m, const void *p, size_t sz) {
5655
assert(p);
5756
assert(sz > 0);
5857

59-
m->iovec[m->n_iovec].iov_base = (void*) p;
60-
m->iovec[m->n_iovec].iov_len = sz;
61-
m->n_iovec++;
58+
m->iovec[m->n_iovec++] = IOVEC_MAKE((void*) p, sz);
6259

6360
return 0;
6461
}
@@ -516,8 +513,7 @@ static int bus_socket_read_auth(sd_bus *b) {
516513

517514
b->rbuffer = p;
518515

519-
iov.iov_base = (uint8_t*) b->rbuffer + b->rbuffer_size;
520-
iov.iov_len = n - b->rbuffer_size;
516+
iov = IOVEC_MAKE((uint8_t *)b->rbuffer + b->rbuffer_size, n - b->rbuffer_size);
521517

522518
if (b->prefer_readv)
523519
k = readv(b->input_fd, &iov, 1);
@@ -634,12 +630,9 @@ static int bus_socket_start_auth_client(sd_bus *b) {
634630
else
635631
auth_suffix = "\r\nBEGIN\r\n";
636632

637-
b->auth_iovec[0].iov_base = (void*) auth_prefix;
638-
b->auth_iovec[0].iov_len = 1 + strlen(auth_prefix + 1);
639-
b->auth_iovec[1].iov_base = (void*) b->auth_buffer;
640-
b->auth_iovec[1].iov_len = l * 2;
641-
b->auth_iovec[2].iov_base = (void*) auth_suffix;
642-
b->auth_iovec[2].iov_len = strlen(auth_suffix);
633+
b->auth_iovec[0] = IOVEC_MAKE((void*) auth_prefix, 1 + strlen(auth_prefix + 1));
634+
b->auth_iovec[1] = IOVEC_MAKE(b->auth_buffer, l * 2);
635+
b->auth_iovec[2] = IOVEC_MAKE_STRING(auth_suffix);
643636

644637
return bus_socket_write_auth(b);
645638
}
@@ -1146,8 +1139,7 @@ int bus_socket_read_message(sd_bus *bus) {
11461139

11471140
bus->rbuffer = b;
11481141

1149-
iov.iov_base = (uint8_t*) bus->rbuffer + bus->rbuffer_size;
1150-
iov.iov_len = need - bus->rbuffer_size;
1142+
iov = IOVEC_MAKE((uint8_t *)bus->rbuffer + bus->rbuffer_size, need - bus->rbuffer_size);
11511143

11521144
if (bus->prefer_readv)
11531145
k = readv(bus->input_fd, &iov, 1);

0 commit comments

Comments
 (0)