From: Yu Watanabe Date: Mon, 6 Mar 2023 00:25:14 +0000 (+0900) Subject: tree-wide: replace IOVEC_INIT with IOVEC_MAKE X-Git-Tag: v254-rc1~1107^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F26686%2Fhead;p=thirdparty%2Fsystemd.git tree-wide: replace IOVEC_INIT with IOVEC_MAKE We use gnu11 to build, hence we can use structured initializer with casting, and it is not necessary to use different patterns on initialization and assignment. Addresses https://github.com/systemd/systemd/pull/26560#discussion_r1118875447. --- diff --git a/src/basic/io-util.h b/src/basic/io-util.h index a5c1f89a8dd..3ad8267962c 100644 --- a/src/basic/io-util.h +++ b/src/basic/io-util.h @@ -75,14 +75,12 @@ static inline bool FILE_SIZE_VALID_OR_INFINITY(uint64_t l) { } #define IOVEC_NULL (struct iovec) {} -#define IOVEC_INIT(base, len) { .iov_base = (base), .iov_len = (len) } -#define IOVEC_MAKE(base, len) (struct iovec) IOVEC_INIT(base, len) -#define IOVEC_INIT_STRING(string) \ +#define IOVEC_MAKE(base, len) (struct iovec) { .iov_base = (base), .iov_len = (len) } +#define IOVEC_MAKE_STRING(string) \ ({ \ char *_s = (char*) (string); \ IOVEC_MAKE(_s, strlen(_s)); \ }) -#define IOVEC_MAKE_STRING(string) IOVEC_INIT_STRING(string) char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value); char* set_iovec_string_field_free(struct iovec *iovec, size_t *n_iovec, const char *field, char *value); diff --git a/src/core/dynamic-user.c b/src/core/dynamic-user.c index c756c1c5248..9f4387a21b3 100644 --- a/src/core/dynamic-user.c +++ b/src/core/dynamic-user.c @@ -298,8 +298,8 @@ static int pick_uid(char **suggested_paths, const char *name, uid_t *ret_uid) { /* Let's store the user name in the lock file, so that we can use it for looking up the username for a UID */ l = pwritev(lock_fd, (struct iovec[2]) { - IOVEC_INIT_STRING(name), - IOVEC_INIT((char[1]) { '\n' }, 1), + IOVEC_MAKE_STRING(name), + IOVEC_MAKE((char[1]) { '\n' }, 1), }, 2, 0); if (l < 0) { r = -errno; @@ -320,7 +320,7 @@ static int pick_uid(char **suggested_paths, const char *name, uid_t *ret_uid) { static int dynamic_user_pop(DynamicUser *d, uid_t *ret_uid, int *ret_lock_fd) { uid_t uid = UID_INVALID; - struct iovec iov = IOVEC_INIT(&uid, sizeof(uid)); + struct iovec iov = IOVEC_MAKE(&uid, sizeof(uid)); int lock_fd; ssize_t k; @@ -342,7 +342,7 @@ static int dynamic_user_pop(DynamicUser *d, uid_t *ret_uid, int *ret_lock_fd) { } static int dynamic_user_push(DynamicUser *d, uid_t uid, int lock_fd) { - struct iovec iov = IOVEC_INIT(&uid, sizeof(uid)); + struct iovec iov = IOVEC_MAKE(&uid, sizeof(uid)); assert(d); diff --git a/src/core/execute.c b/src/core/execute.c index dda8736804c..085b03aeb8e 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -3992,9 +3992,9 @@ static int send_user_lookup( if (writev(user_lookup_fd, (struct iovec[]) { - IOVEC_INIT(&uid, sizeof(uid)), - IOVEC_INIT(&gid, sizeof(gid)), - IOVEC_INIT_STRING(unit->id) }, 3) < 0) + IOVEC_MAKE(&uid, sizeof(uid)), + IOVEC_MAKE(&gid, sizeof(gid)), + IOVEC_MAKE_STRING(unit->id) }, 3) < 0) return -errno; return 0; diff --git a/src/portable/portable.c b/src/portable/portable.c index 377e1a99370..eb807b0eb74 100644 --- a/src/portable/portable.c +++ b/src/portable/portable.c @@ -434,7 +434,7 @@ static int portable_extract_by_path( * identical to NAME_MAX. For now we use that, but this should be updated one day when the final * limit is known. */ char iov_buffer[PATH_MAX + NAME_MAX + 2]; - struct iovec iov = IOVEC_INIT(iov_buffer, sizeof(iov_buffer)); + struct iovec iov = IOVEC_MAKE(iov_buffer, sizeof(iov_buffer)); ssize_t n = receive_one_fd_iov(seq[0], &iov, 1, 0, &fd); if (n == -EIO) diff --git a/src/test/test-socket-util.c b/src/test/test-socket-util.c index dbafe8b0589..71ec766ca18 100644 --- a/src/test/test-socket-util.c +++ b/src/test/test-socket-util.c @@ -248,7 +248,7 @@ TEST(passfd_read) { /* Parent */ char buf[64]; - struct iovec iov = IOVEC_INIT(buf, sizeof(buf)-1); + struct iovec iov = IOVEC_MAKE(buf, sizeof(buf)-1); _cleanup_close_ int fd; pair[1] = safe_close(pair[1]); @@ -275,7 +275,7 @@ TEST(passfd_contents_read) { if (r == 0) { /* Child */ - struct iovec iov = IOVEC_INIT_STRING(wire_contents); + struct iovec iov = IOVEC_MAKE_STRING(wire_contents); char tmpfile[] = "/tmp/test-socket-util-passfd-contents-read-XXXXXX"; pair[0] = safe_close(pair[0]); @@ -292,7 +292,7 @@ TEST(passfd_contents_read) { /* Parent */ char buf[64]; - struct iovec iov = IOVEC_INIT(buf, sizeof(buf)-1); + struct iovec iov = IOVEC_MAKE(buf, sizeof(buf)-1); _cleanup_close_ int fd; ssize_t k; @@ -322,7 +322,7 @@ TEST(receive_nopassfd) { if (r == 0) { /* Child */ - struct iovec iov = IOVEC_INIT_STRING(wire_contents); + struct iovec iov = IOVEC_MAKE_STRING(wire_contents); pair[0] = safe_close(pair[0]); @@ -332,7 +332,7 @@ TEST(receive_nopassfd) { /* Parent */ char buf[64]; - struct iovec iov = IOVEC_INIT(buf, sizeof(buf)-1); + struct iovec iov = IOVEC_MAKE(buf, sizeof(buf)-1); int fd = -999; ssize_t k; @@ -366,7 +366,7 @@ TEST(send_nodata_nofd) { /* Parent */ char buf[64]; - struct iovec iov = IOVEC_INIT(buf, sizeof(buf)-1); + struct iovec iov = IOVEC_MAKE(buf, sizeof(buf)-1); int fd = -999; ssize_t k; @@ -391,7 +391,7 @@ TEST(send_emptydata) { if (r == 0) { /* Child */ - struct iovec iov = IOVEC_INIT_STRING(""); /* zero-length iov */ + struct iovec iov = IOVEC_MAKE_STRING(""); /* zero-length iov */ assert_se(iov.iov_len == 0); pair[0] = safe_close(pair[0]); @@ -403,7 +403,7 @@ TEST(send_emptydata) { /* Parent */ char buf[64]; - struct iovec iov = IOVEC_INIT(buf, sizeof(buf)-1); + struct iovec iov = IOVEC_MAKE(buf, sizeof(buf)-1); int fd = -999; ssize_t k;