]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
iovec-util: make IOVEC_TOTAL_SIZE() a regular function
authorLennart Poettering <lennart@poettering.net>
Thu, 19 Oct 2023 14:33:51 +0000 (16:33 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 20 Oct 2023 08:43:50 +0000 (10:43 +0200)
The function isn't necessarily fast (it's O(n)), and there's no reason
to have it defined as inline function, since it's neither fast, nor
entirely trivial.

src/basic/iovec-util.c
src/basic/iovec-util.h
src/journal/journald-server.c
src/libsystemd/sd-bus/bus-message.c
src/libsystemd/sd-daemon/sd-daemon.c
src/resolve/resolved-dnstls-gnutls.c
src/resolve/resolved-dnstls-openssl.c

index 89c1af34f11fde1179447da3fefce73453f0b752..500ac33bbdb337e2fc0afe3fd2b01b93a0d72c8f 100644 (file)
@@ -3,6 +3,16 @@
 #include "iovec-util.h"
 #include "string-util.h"
 
+size_t iovec_total_size(const struct iovec *i, size_t n) {
+        size_t sum = 0;
+
+        assert(i || n == 0);
+
+        FOREACH_ARRAY(j, i, n)
+                sum += j->iov_len;
+
+        return sum;
+}
 
 char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value) {
         char *x;
index 7ee72671c4dad38cc8149f1d3ba9939444fcc14c..670f57464ac9b1350dbe4acf8717fed4060e937d 100644 (file)
@@ -7,14 +7,7 @@
 
 #include "macro.h"
 
-static inline size_t IOVEC_TOTAL_SIZE(const struct iovec *i, size_t n) {
-        size_t r = 0;
-
-        for (size_t j = 0; j < n; j++)
-                r += i[j].iov_len;
-
-        return r;
-}
+size_t iovec_total_size(const struct iovec *i, size_t n);
 
 static inline bool IOVEC_INCREMENT(struct iovec *i, size_t n, size_t k) {
         /* Returns true if there is nothing else to send (bytes written cover all of the iovec),
index 8712d72acf0266481a3b6fd88b1f4b5b94187afe..58e23f7f76edd715b4ed068c286b794a9520b999 100644 (file)
@@ -962,7 +962,7 @@ static void server_write_to_journal(
                 return;
         }
 
-        log_debug_errno(r, "Failed to write entry to %s (%zu items, %zu bytes): %m", f->path, n, IOVEC_TOTAL_SIZE(iovec, n));
+        log_debug_errno(r, "Failed to write entry to %s (%zu items, %zu bytes): %m", f->path, n, iovec_total_size(iovec, n));
 
         if (!shall_try_append_again(f, r))
                 return;
@@ -992,7 +992,7 @@ static void server_write_to_journal(
         if (r < 0)
                 log_ratelimit_error_errno(r, FAILED_TO_WRITE_ENTRY_RATELIMIT,
                                           "Failed to write entry to %s (%zu items, %zu bytes) despite vacuuming, ignoring: %m",
-                                          f->path, n, IOVEC_TOTAL_SIZE(iovec, n));
+                                          f->path, n, iovec_total_size(iovec, n));
         else
                 server_schedule_sync(s, priority);
 }
index 150e7c9b9ecf23cc534776367b1f491dd4c003df..f0818b801ca006f71aca630ec56e82fe31ba8ec4 100644 (file)
@@ -1506,7 +1506,7 @@ _public_ int sd_bus_message_append_string_iovec(
         assert_return(iov || n == 0, -EINVAL);
         assert_return(!m->poisoned, -ESTALE);
 
-        size = IOVEC_TOTAL_SIZE(iov, n);
+        size = iovec_total_size(iov, n);
 
         r = sd_bus_message_append_string_space(m, size, &p);
         if (r < 0)
@@ -2160,7 +2160,7 @@ _public_ int sd_bus_message_append_array_iovec(
         assert_return(iov || n == 0, -EINVAL);
         assert_return(!m->poisoned, -ESTALE);
 
-        size = IOVEC_TOTAL_SIZE(iov, n);
+        size = iovec_total_size(iov, n);
 
         r = sd_bus_message_append_array_space(m, type, size, &p);
         if (r < 0)
index 5fccf0d760748b28887c7c5c22837e96547abee5..8986596b70d8878856263bf9b87f8b1b3a5112e9 100644 (file)
@@ -585,7 +585,7 @@ static int pid_notify_with_fds_internal(
                         send_ucred = false;
                 } else {
                         /* Unless we're using SOCK_STREAM, we expect to write all the contents immediately. */
-                        if (type != SOCK_STREAM && (size_t) n < IOVEC_TOTAL_SIZE(msghdr.msg_iov, msghdr.msg_iovlen))
+                        if (type != SOCK_STREAM && (size_t) n < iovec_total_size(msghdr.msg_iov, msghdr.msg_iovlen))
                                 return -EIO;
 
                         /* Make sure we only send fds and ucred once, even if we're using SOCK_STREAM. */
index acdad6fa9109488b13b3a5e89204ee9bc9c912b9..61f38ef4b4ca9bfcca7f821951e3d47fc2406b3e 100644 (file)
@@ -171,7 +171,7 @@ ssize_t dnstls_stream_writev(DnsStream *stream, const struct iovec *iov, size_t
         assert(stream->encrypted);
         assert(stream->dnstls_data.session);
         assert(iov);
-        assert(IOVEC_TOTAL_SIZE(iov, iovcnt) > 0);
+        assert(iovec_total_size(iov, iovcnt) > 0);
 
         gnutls_record_cork(stream->dnstls_data.session);
 
index 4a0132ad3d8fe83f313a51fa4877b19277b879b3..b217417a1ac8e89e7621012197e4d503f6875ae1 100644 (file)
@@ -322,14 +322,14 @@ ssize_t dnstls_stream_writev(DnsStream *stream, const struct iovec *iov, size_t
         assert(stream->encrypted);
         assert(stream->dnstls_data.ssl);
         assert(iov);
-        assert(IOVEC_TOTAL_SIZE(iov, iovcnt) > 0);
+        assert(iovec_total_size(iov, iovcnt) > 0);
 
         if (iovcnt == 1)
                 return dnstls_stream_write(stream, iov[0].iov_base, iov[0].iov_len);
 
         /* As of now, OpenSSL can not accumulate multiple writes, so join into a
            single buffer. Suboptimal, but better than multiple SSL_write calls. */
-        count = IOVEC_TOTAL_SIZE(iov, iovcnt);
+        count = iovec_total_size(iov, iovcnt);
         buf = new(char, count);
         for (size_t i = 0, pos = 0; i < iovcnt; pos += iov[i].iov_len, i++)
                 memcpy(buf + pos, iov[i].iov_base, iov[i].iov_len);