From 1ca0b482b614f8b7772caba372c83bc4f9e63ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 23 Oct 2023 14:51:43 +0200 Subject: [PATCH 1/4] basic/iovec-util: always call the iovec "iovec" We were using "i", "iov", and "iovec" in variuos places. Let's be consistent. --- src/basic/iovec-util.c | 20 ++++++++++---------- src/basic/iovec-util.h | 10 +++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/basic/iovec-util.c b/src/basic/iovec-util.c index 11aa630ae6a..5d70657784c 100644 --- a/src/basic/iovec-util.c +++ b/src/basic/iovec-util.c @@ -3,24 +3,24 @@ #include "iovec-util.h" #include "string-util.h" -size_t iovec_total_size(const struct iovec *i, size_t n) { +size_t iovec_total_size(const struct iovec *iovec, size_t n) { size_t sum = 0; - assert(i || n == 0); + assert(iovec || n == 0); - FOREACH_ARRAY(j, i, n) + FOREACH_ARRAY(j, iovec, n) sum += j->iov_len; return sum; } -bool iovec_increment(struct iovec *i, size_t n, size_t k) { - assert(i || n == 0); +bool iovec_increment(struct iovec *iovec, size_t n, size_t k) { + assert(iovec || n == 0); /* Returns true if there is nothing else to send (bytes written cover all of the iovec), * false if there's still work to do. */ - FOREACH_ARRAY(j, i, n) { + FOREACH_ARRAY(j, iovec, n) { size_t sub; if (j->iov_len == 0) @@ -62,12 +62,12 @@ char* set_iovec_string_field_free(struct iovec *iovec, size_t *n_iovec, const ch return x; } -void iovec_array_free(struct iovec *iov, size_t n) { - if (!iov) +void iovec_array_free(struct iovec *iovec, size_t n) { + if (!iovec) return; for (size_t i = 0; i < n; i++) - free(iov[i].iov_base); + free(iovec[i].iov_base); - free(iov); + free(iovec); } diff --git a/src/basic/iovec-util.h b/src/basic/iovec-util.h index 1f652a0ede6..9c3134592ed 100644 --- a/src/basic/iovec-util.h +++ b/src/basic/iovec-util.h @@ -8,9 +8,9 @@ #include "alloc-util.h" #include "macro.h" -size_t iovec_total_size(const struct iovec *i, size_t n); +size_t iovec_total_size(const struct iovec *iovec, size_t n); -bool iovec_increment(struct iovec *i, size_t n, size_t k); +bool iovec_increment(struct iovec *iovec, size_t n, size_t k); #define IOVEC_NULL (const struct iovec) {} @@ -38,11 +38,11 @@ static inline void iovec_done_erase(struct iovec *iovec) { iovec->iov_len = 0; } -static inline bool iovec_is_set(const struct iovec *iov) { - return iov && iov->iov_len > 0 && iov->iov_base; +static inline bool iovec_is_set(const struct iovec *iovec) { + return iovec && iovec->iov_len > 0 && iovec->iov_base; } 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); -void iovec_array_free(struct iovec *iov, size_t n); +void iovec_array_free(struct iovec *iovec, size_t n); From 7dc951ef91bac7b8ab553213709462ef74f60375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 23 Oct 2023 14:59:17 +0200 Subject: [PATCH 2/4] basic/iovec-util: drop IOVEC_NULL The macro isn't very useful, we can just use the direct setting to increase readability. --- src/basic/iovec-util.h | 4 +--- src/libsystemd/sd-journal/journal-send.c | 2 +- src/partition/repart.c | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/basic/iovec-util.h b/src/basic/iovec-util.h index 9c3134592ed..ad6e1275d51 100644 --- a/src/basic/iovec-util.h +++ b/src/basic/iovec-util.h @@ -12,8 +12,6 @@ size_t iovec_total_size(const struct iovec *iovec, size_t n); bool iovec_increment(struct iovec *iovec, size_t n, size_t k); -#define IOVEC_NULL (const struct iovec) {} - #define IOVEC_MAKE(base, len) (struct iovec) { .iov_base = (base), .iov_len = (len) } #define IOVEC_MAKE_STRING(string) \ ({ \ @@ -21,7 +19,7 @@ bool iovec_increment(struct iovec *iovec, size_t n, size_t k); IOVEC_MAKE((char*) _s, strlen(_s)); \ }) -#define TAKE_IOVEC(p) TAKE_GENERIC((p), struct iovec, IOVEC_NULL) +#define TAKE_IOVEC(p) TAKE_GENERIC((p), struct iovec, {}) static inline void iovec_done(struct iovec *iovec) { /* A _cleanup_() helper that frees the iov_base in the iovec */ diff --git a/src/libsystemd/sd-journal/journal-send.c b/src/libsystemd/sd-journal/journal-send.c index 1ca721e6c94..be23b2fe75d 100644 --- a/src/libsystemd/sd-journal/journal-send.c +++ b/src/libsystemd/sd-journal/journal-send.c @@ -530,7 +530,7 @@ _public_ int sd_journal_send_with_location(const char *file, const char *line, c r = sd_journal_sendv(iov, n_iov); - iov[0] = iov[1] = iov[2] = IOVEC_NULL; + iov[0] = iov[1] = iov[2] = (struct iovec) {}; return r; } diff --git a/src/partition/repart.c b/src/partition/repart.c index 4e57f977266..e6725ed352f 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -4139,7 +4139,7 @@ static int sign_verity_roothash( static int partition_format_verity_sig(Context *context, Partition *p) { _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; - _cleanup_(iovec_done) struct iovec sig = IOVEC_NULL; + _cleanup_(iovec_done) struct iovec sig = {}; _cleanup_free_ char *text = NULL, *hint = NULL; Partition *hp; uint8_t fp[X509_FINGERPRINT_SIZE]; From 3c9783c7f4b16c1eb702dfed1fc4f980efcb8f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 23 Oct 2023 22:23:07 +0200 Subject: [PATCH 3/4] basic/iovec-util: drop TAKE_IOVEC As suggested in https://github.com/systemd/systemd/pull/29679#discussion_r1368678932. --- src/basic/iovec-util.h | 2 -- src/partition/repart.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/basic/iovec-util.h b/src/basic/iovec-util.h index ad6e1275d51..39feabd4260 100644 --- a/src/basic/iovec-util.h +++ b/src/basic/iovec-util.h @@ -19,8 +19,6 @@ bool iovec_increment(struct iovec *iovec, size_t n, size_t k); IOVEC_MAKE((char*) _s, strlen(_s)); \ }) -#define TAKE_IOVEC(p) TAKE_GENERIC((p), struct iovec, {}) - static inline void iovec_done(struct iovec *iovec) { /* A _cleanup_() helper that frees the iov_base in the iovec */ assert(iovec); diff --git a/src/partition/repart.c b/src/partition/repart.c index e6725ed352f..9109ea18237 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -4087,7 +4087,7 @@ static int partition_format_verity_hash( p->new_uuid_is_set = true; } - p->roothash = TAKE_IOVEC(rh); + p->roothash = TAKE_STRUCT(rh); return 0; #else From 1dd33bf3e4a4390627324e633180eddd84c1c212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 23 Oct 2023 22:30:28 +0200 Subject: [PATCH 4/4] basic/iovec-util: use FOREACH_ARRAY in one more place --- src/basic/iovec-util.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/basic/iovec-util.c b/src/basic/iovec-util.c index 5d70657784c..991889a14eb 100644 --- a/src/basic/iovec-util.c +++ b/src/basic/iovec-util.c @@ -63,11 +63,8 @@ char* set_iovec_string_field_free(struct iovec *iovec, size_t *n_iovec, const ch } void iovec_array_free(struct iovec *iovec, size_t n) { - if (!iovec) - return; - - for (size_t i = 0; i < n; i++) - free(iovec[i].iov_base); + FOREACH_ARRAY(i, iovec, n) + free(i->iov_base); free(iovec); }