]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
iovec-util: make IOVEC_INCREMENT a regular function too
authorLennart Poettering <lennart@poettering.net>
Thu, 19 Oct 2023 14:36:43 +0000 (16:36 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 20 Oct 2023 08:43:50 +0000 (10:43 +0200)
Even more than with the previous commit, this is not a trivial function
and there's no reason to believe this will actually be inlined nor that
it would be beneficial.

src/basic/iovec-util.c
src/basic/iovec-util.h
src/basic/log.c
src/fuzz/fuzz-varlink.c
src/libsystemd/sd-daemon/sd-daemon.c
src/resolve/resolved-dns-stream.c

index 500ac33bbdb337e2fc0afe3fd2b01b93a0d72c8f..11aa630ae6a0e6a20dbd18730f9034e030899857 100644 (file)
@@ -14,6 +14,31 @@ size_t iovec_total_size(const struct iovec *i, size_t n) {
         return sum;
 }
 
+bool iovec_increment(struct iovec *i, size_t n, size_t k) {
+        assert(i || 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) {
+                size_t sub;
+
+                if (j->iov_len == 0)
+                        continue;
+                if (k == 0)
+                        return false;
+
+                sub = MIN(j->iov_len, k);
+                j->iov_len -= sub;
+                j->iov_base = (uint8_t*) j->iov_base + sub;
+                k -= sub;
+        }
+
+        assert(k == 0); /* Anything else would mean that we wrote more bytes than available,
+                         * or the kernel reported writing more bytes than sent. */
+        return true;
+}
+
 char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value) {
         char *x;
 
index 245c61601767f9b0f552672cfcfe9776f8c7abb4..1f72898cba08fc4a73f961dd51872a3dd332c209 100644 (file)
@@ -9,28 +9,7 @@
 
 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),
-         * false if there's still work to do. */
-
-        for (size_t j = 0; j < n; j++) {
-                size_t sub;
-
-                if (i[j].iov_len == 0)
-                        continue;
-                if (k == 0)
-                        return false;
-
-                sub = MIN(i[j].iov_len, k);
-                i[j].iov_len -= sub;
-                i[j].iov_base = (uint8_t*) i[j].iov_base + sub;
-                k -= sub;
-        }
-
-        assert(k == 0); /* Anything else would mean that we wrote more bytes than available,
-                         * or the kernel reported writing more bytes than sent. */
-        return true;
-}
+bool iovec_increment(struct iovec *i, size_t n, size_t k);
 
 #define IOVEC_NULL (const struct iovec) {}
 
index b05620907b2c409d1d2aac036eacb76fca0088d6..e7fe84611ee1d55c6f87abc73c77283e3cbff185 100644 (file)
@@ -541,7 +541,7 @@ static int write_to_syslog(
                 if (!syslog_is_stream)
                         break;
 
-                if (IOVEC_INCREMENT(iovec, ELEMENTSOF(iovec), n))
+                if (iovec_increment(iovec, ELEMENTSOF(iovec), n))
                         break;
         }
 
index e98929d1c61da30a634de526556b7018c3f80f81..18db78ce983d54b584ac96e95cec27ec2bb13e4b 100644 (file)
@@ -41,7 +41,7 @@ static int io_callback(sd_event_source *s, int fd, uint32_t revents, void *userd
                         else
                                 assert_se(errno == EAGAIN);
                 } else
-                        IOVEC_INCREMENT(iov, 1, n);
+                        iovec_increment(iov, 1, n);
         }
 
         if (revents & EPOLLIN) {
index 8986596b70d8878856263bf9b87f8b1b3a5112e9..7c370ab7bc4db7ba0f0b7cdb8cb1dfa47ee6c2a1 100644 (file)
@@ -592,7 +592,7 @@ static int pid_notify_with_fds_internal(
                         msghdr.msg_control = NULL;
                         msghdr.msg_controllen = 0;
                 }
-        } while (!IOVEC_INCREMENT(msghdr.msg_iov, msghdr.msg_iovlen, n));
+        } while (!iovec_increment(msghdr.msg_iov, msghdr.msg_iovlen, n));
 
         return 1;
 }
index bc01613b51f51bb43898ed7d3be0975cc824f2d1..ddd1db5e09a9785a509abbad0a13fe003eafe33f 100644 (file)
@@ -331,7 +331,7 @@ static int on_stream_io(sd_event_source *es, int fd, uint32_t revents, void *use
                         IOVEC_MAKE(DNS_PACKET_DATA(s->write_packet), s->write_packet->size),
                 };
 
-                IOVEC_INCREMENT(iov, ELEMENTSOF(iov), s->n_written);
+                iovec_increment(iov, ELEMENTSOF(iov), s->n_written);
 
                 ssize_t ss = dns_stream_writev(s, iov, ELEMENTSOF(iov), 0);
                 if (ss < 0) {