From: Mike Yuan Date: Tue, 5 Sep 2023 14:15:09 +0000 (+0800) Subject: io-util: introduce loop_write_full that takes a timeout X-Git-Tag: v255-rc1~550^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e22c60a9d5dfc5f0b260c7906f3546aef2925998;p=thirdparty%2Fsystemd.git io-util: introduce loop_write_full that takes a timeout Also drop do_poll as the use case is covered by timeout. --- diff --git a/src/basic/compress.c b/src/basic/compress.c index 10e7aaec59d..ac0bfdfcd5f 100644 --- a/src/basic/compress.c +++ b/src/basic/compress.c @@ -614,7 +614,7 @@ int compress_stream_xz(int fdf, int fdt, uint64_t max_bytes, uint64_t *ret_uncom n = sizeof(out) - s.avail_out; - k = loop_write(fdt, out, n, false); + k = loop_write(fdt, out, n); if (k < 0) return k; @@ -693,7 +693,7 @@ int compress_stream_lz4(int fdf, int fdt, uint64_t max_bytes, uint64_t *ret_unco "Compressed stream longer than %" PRIu64 " bytes", max_bytes); if (out_allocsize - offset < frame_size + 4) { - k = loop_write(fdt, out_buff, offset, false); + k = loop_write(fdt, out_buff, offset); if (k < 0) return k; offset = 0; @@ -706,7 +706,7 @@ int compress_stream_lz4(int fdf, int fdt, uint64_t max_bytes, uint64_t *ret_unco offset += n; total_out += n; - r = loop_write(fdt, out_buff, offset, false); + r = loop_write(fdt, out_buff, offset); if (r < 0) return r; @@ -779,7 +779,7 @@ int decompress_stream_xz(int fdf, int fdt, uint64_t max_bytes) { max_bytes -= n; } - k = loop_write(fdt, out, n, false); + k = loop_write(fdt, out, n); if (k < 0) return k; @@ -845,7 +845,7 @@ int decompress_stream_lz4(int in, int out, uint64_t max_bytes) { goto cleanup; } - r = loop_write(out, buf, produced, false); + r = loop_write(out, buf, produced); if (r < 0) goto cleanup; } @@ -931,7 +931,7 @@ int compress_stream_zstd(int fdf, int fdt, uint64_t max_bytes, uint64_t *ret_unc if (left < output.pos) return -EFBIG; - wrote = loop_write(fdt, output.dst, output.pos, 1); + wrote = loop_write_full(fdt, output.dst, output.pos, USEC_INFINITY); if (wrote < 0) return wrote; @@ -1041,7 +1041,7 @@ int decompress_stream_zstd(int fdf, int fdt, uint64_t max_bytes) { if (left < output.pos) return -EFBIG; - wrote = loop_write(fdt, output.dst, output.pos, 1); + wrote = loop_write_full(fdt, output.dst, output.pos, USEC_INFINITY); if (wrote < 0) return wrote; diff --git a/src/basic/efivars.c b/src/basic/efivars.c index cb239bdf18c..9011ae29a3a 100644 --- a/src/basic/efivars.c +++ b/src/basic/efivars.c @@ -232,7 +232,7 @@ int efi_set_variable(const char *variable, const void *value, size_t size) { buf->attr = attr; memcpy(buf->buf, value, size); - r = loop_write(fd, buf, sizeof(uint32_t) + size, false); + r = loop_write(fd, buf, sizeof(uint32_t) + size); if (r < 0) goto finish; diff --git a/src/basic/io-util.c b/src/basic/io-util.c index 7f3b092f59d..25831e47dc1 100644 --- a/src/basic/io-util.c +++ b/src/basic/io-util.c @@ -5,6 +5,7 @@ #include #include +#include "errno-util.h" #include "io-util.h" #include "string-util.h" #include "time-util.h" @@ -105,18 +106,19 @@ int loop_read_exact(int fd, void *buf, size_t nbytes, bool do_poll) { return 0; } -int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) { +int loop_write_full(int fd, const void *buf, size_t nbytes, usec_t timeout) { const uint8_t *p; + usec_t end; + int r; assert(fd >= 0); + assert(buf || nbytes == 0); if (nbytes == 0) { static const dummy_t dummy[0]; assert_cc(sizeof(dummy) == 0); p = (const void*) dummy; /* Some valid pointer, in case NULL was specified */ } else { - assert(buf); - if (nbytes == SIZE_MAX) nbytes = strlen(buf); else if (_unlikely_(nbytes > (size_t) SSIZE_MAX)) @@ -125,6 +127,9 @@ int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) { p = buf; } + /* When timeout is 0 or USEC_INFINITY this is not used. But we initialize it to a sensible value. */ + end = timestamp_is_set(timeout) ? usec_add(now(CLOCK_MONOTONIC), timeout) : USEC_INFINITY; + do { ssize_t k; @@ -133,16 +138,30 @@ int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) { if (errno == EINTR) continue; - if (errno == EAGAIN && do_poll) { - /* We knowingly ignore any return value here, - * and expect that any error/EOF is reported - * via write() */ + if (errno != EAGAIN || timeout == 0) + return -errno; - (void) fd_wait_for_event(fd, POLLOUT, USEC_INFINITY); - continue; + usec_t wait_for; + + if (timeout == USEC_INFINITY) + wait_for = USEC_INFINITY; + else { + usec_t t = now(CLOCK_MONOTONIC); + if (t >= end) + return -ETIME; + + wait_for = usec_sub_unsigned(end, t); } - return -errno; + r = fd_wait_for_event(fd, POLLOUT, wait_for); + if (timeout == USEC_INFINITY || ERRNO_IS_NEG_TRANSIENT(r)) + /* If timeout == USEC_INFINITY we knowingly ignore any return value + * here, and expect that any error/EOF is reported via write() */ + continue; + if (r < 0) + return r; + if (r == 0) + return -ETIME; } if (_unlikely_(nbytes > 0 && k == 0)) /* Can't really happen */ diff --git a/src/basic/io-util.h b/src/basic/io-util.h index 336c9ce79b0..2a1b2fe5da5 100644 --- a/src/basic/io-util.h +++ b/src/basic/io-util.h @@ -15,7 +15,11 @@ int flush_fd(int fd); ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll); int loop_read_exact(int fd, void *buf, size_t nbytes, bool do_poll); -int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll); + +int loop_write_full(int fd, const void *buf, size_t nbytes, usec_t timeout); +static inline int loop_write(int fd, const void *buf, size_t nbytes) { + return loop_write_full(fd, buf, nbytes, 0); +} int pipe_eof(int fd); diff --git a/src/basic/random-util.c b/src/basic/random-util.c index d4a3c9ca5c9..c7277ad01ee 100644 --- a/src/basic/random-util.c +++ b/src/basic/random-util.c @@ -223,7 +223,7 @@ int random_write_entropy(int fd, const void *seed, size_t size, bool credit) { if (ioctl(fd, RNDADDENTROPY, info) < 0) return -errno; } else { - r = loop_write(fd, seed, size, false); + r = loop_write(fd, seed, size); if (r < 0) return r; } diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 2575a658b16..63594f07cf0 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -569,7 +569,7 @@ int vt_disallocate(const char *name) { "\033[r" /* clear scrolling region */ "\033[H" /* move home */ "\033[3J", /* clear screen including scrollback, requires Linux 2.6.40 */ - 10, false); + 10); return 0; } @@ -1544,7 +1544,7 @@ int set_terminal_cursor_position(int fd, unsigned int row, unsigned int column) xsprintf(cursor_position, "\x1B[%u;%uH", row, column); - r = loop_write(fd, cursor_position, SIZE_MAX, /* do_poll = */false); + r = loop_write(fd, cursor_position, SIZE_MAX); if (r < 0) return log_warning_errno(r, "Failed to set cursor position, ignoring: %m"); diff --git a/src/battery-check/battery-check.c b/src/battery-check/battery-check.c index 940885b3a3f..5d7c6a58ae5 100644 --- a/src/battery-check/battery-check.c +++ b/src/battery-check/battery-check.c @@ -82,7 +82,7 @@ static int plymouth_send_message(const char *mode, const char *message) { return log_full_errno(ERRNO_IS_NO_PLYMOUTH(errno) ? LOG_DEBUG : LOG_WARNING, errno, "Failed to connect to plymouth: %m"); - r = loop_write(fd, plymouth_message, c, /* do_poll = */ false); + r = loop_write(fd, plymouth_message, c); if (r < 0) return log_full_errno(ERRNO_IS_NO_PLYMOUTH(r) ? LOG_DEBUG : LOG_WARNING, r, "Failed to write to plymouth: %m"); diff --git a/src/boot/bootctl-random-seed.c b/src/boot/bootctl-random-seed.c index 95ff73cc875..cfe10c4115e 100644 --- a/src/boot/bootctl-random-seed.c +++ b/src/boot/bootctl-random-seed.c @@ -184,7 +184,7 @@ int install_random_seed(const char *esp) { if (!warned) /* only warn once per seed file */ (void) random_seed_verify_permissions(fd, S_IFREG); - r = loop_write(fd, buffer, sizeof(buffer), /* do_poll= */ false); + r = loop_write(fd, buffer, sizeof(buffer)); if (r < 0) { log_error_errno(r, "Failed to write random seed file: %m"); goto fail; diff --git a/src/core/exec-credential.c b/src/core/exec-credential.c index 2a72f1c3961..4d4dadca90d 100644 --- a/src/core/exec-credential.c +++ b/src/core/exec-credential.c @@ -182,7 +182,7 @@ static int write_credential( return -errno; } - r = loop_write(fd, data, size, /* do_poll = */ false); + r = loop_write(fd, data, size); if (r < 0) return r; diff --git a/src/core/import-creds.c b/src/core/import-creds.c index 0e0bb06dc47..48f31609231 100644 --- a/src/core/import-creds.c +++ b/src/core/import-creds.c @@ -339,7 +339,7 @@ static int proc_cmdline_callback(const char *key, const char *value, void *data) if (nfd < 0) return nfd; - r = loop_write(nfd, d, l, /* do_poll= */ false); + r = loop_write(nfd, d, l); if (r < 0) { (void) unlinkat(c->target_dir_fd, n, 0); return log_error_errno(r, "Failed to write credential: %m"); @@ -551,7 +551,7 @@ static int parse_smbios_strings(ImportCredentialContext *c, const char *data, si if (nfd < 0) return nfd; - r = loop_write(nfd, cdata, cdata_len, /* do_poll= */ false); + r = loop_write(nfd, cdata, cdata_len); if (r < 0) { (void) unlinkat(c->target_dir_fd, cn, 0); return log_error_errno(r, "Failed to write credential: %m"); diff --git a/src/import/import-raw.c b/src/import/import-raw.c index 4c9a30292b2..feb6ac1bdda 100644 --- a/src/import/import-raw.c +++ b/src/import/import-raw.c @@ -378,7 +378,7 @@ static int raw_import_write(const void *p, size_t sz, void *userdata) { if ((size_t) n < sz) return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short write"); } else { - r = loop_write(i->output_fd, p, sz, false); + r = loop_write(i->output_fd, p, sz); if (r < 0) return log_error_errno(r, "Failed to write file: %m"); } diff --git a/src/import/import-tar.c b/src/import/import-tar.c index ff32ae4e592..8c184578169 100644 --- a/src/import/import-tar.c +++ b/src/import/import-tar.c @@ -250,7 +250,7 @@ static int tar_import_write(const void *p, size_t sz, void *userdata) { TarImport *i = userdata; int r; - r = loop_write(i->tar_fd, p, sz, false); + r = loop_write(i->tar_fd, p, sz); if (r < 0) return r; diff --git a/src/import/pull-common.c b/src/import/pull-common.c index 3b80e64b328..a3d4bc8433a 100644 --- a/src/import/pull-common.c +++ b/src/import/pull-common.c @@ -400,7 +400,7 @@ static int verify_gpg( if (sig_file < 0) return log_error_errno(errno, "Failed to create temporary file: %m"); - r = loop_write(sig_file, signature, signature_size, false); + r = loop_write(sig_file, signature, signature_size); if (r < 0) { log_error_errno(r, "Failed to write to temporary file: %m"); goto finish; @@ -465,7 +465,7 @@ static int verify_gpg( gpg_pipe[0] = safe_close(gpg_pipe[0]); - r = loop_write(gpg_pipe[1], payload, payload_size, false); + r = loop_write(gpg_pipe[1], payload, payload_size); if (r < 0) { log_error_errno(r, "Failed to write to pipe: %m"); goto finish; diff --git a/src/import/pull-job.c b/src/import/pull-job.c index 8dd8ac09158..d05bf3cd497 100644 --- a/src/import/pull-job.c +++ b/src/import/pull-job.c @@ -336,7 +336,7 @@ static int pull_job_write_uncompressed(const void *p, size_t sz, void *userdata) if ((size_t) n < sz) return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short write"); } else { - r = loop_write(j->disk_fd, p, sz, false); + r = loop_write(j->disk_fd, p, sz); if (r < 0) return log_error_errno(r, "Failed to write file: %m"); } diff --git a/src/journal/bsod.c b/src/journal/bsod.c index 4e7090cda93..512536412d4 100644 --- a/src/journal/bsod.c +++ b/src/journal/bsod.c @@ -166,7 +166,7 @@ static int display_emergency_message_fullscreen(const char *message) { if (ioctl(fd, VT_ACTIVATE, free_vt + 1) < 0) return log_error_errno(errno, "Failed to activate tty: %m"); - r = loop_write(fd, ANSI_BACKGROUND_BLUE ANSI_HOME_CLEAR, SIZE_MAX, /* do_poll = */ false); + r = loop_write(fd, ANSI_BACKGROUND_BLUE ANSI_HOME_CLEAR, SIZE_MAX); if (r < 0) log_warning_errno(r, "Failed to clear terminal, ignoring: %m"); @@ -174,7 +174,7 @@ static int display_emergency_message_fullscreen(const char *message) { if (r < 0) log_warning_errno(r, "Failed to move terminal cursor position, ignoring: %m"); - r = loop_write(fd, "The current boot has failed!", SIZE_MAX, /* do_poll = */false); + r = loop_write(fd, "The current boot has failed!", SIZE_MAX); if (r < 0) return log_warning_errno(r, "Failed to write to terminal: %m"); @@ -184,7 +184,7 @@ static int display_emergency_message_fullscreen(const char *message) { if (r < 0) log_warning_errno(r, "Failed to move terminal cursor position, ignoring: %m"); - r = loop_write(fd, message, SIZE_MAX, /* do_poll = */false); + r = loop_write(fd, message, SIZE_MAX); if (r < 0) return log_warning_errno(r, "Failed to write emergency message to terminal: %m"); @@ -200,7 +200,7 @@ static int display_emergency_message_fullscreen(const char *message) { if (r < 0) log_warning_errno(r, "Failed to move terminal cursor position, ignoring: %m"); - r = loop_write(fd, "Press any key to exit...", SIZE_MAX, /* do_poll = */false); + r = loop_write(fd, "Press any key to exit...", SIZE_MAX); if (r < 0) return log_warning_errno(r, "Failed to write to terminal: %m"); diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 48747929beb..9a1bfc1e7dc 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -1914,11 +1914,11 @@ static int setup_keys(void) { .fsprg_state_size = htole64(state_size), }; - r = loop_write(fd, &h, sizeof(h), false); + r = loop_write(fd, &h, sizeof(h)); if (r < 0) return log_error_errno(r, "Failed to write header: %m"); - r = loop_write(fd, state, state_size, false); + r = loop_write(fd, state, state_size); if (r < 0) return log_error_errno(r, "Failed to write state: %m"); diff --git a/src/libsystemd/sd-id128/id128-util.c b/src/libsystemd/sd-id128/id128-util.c index 9d391de1664..596b8786bf6 100644 --- a/src/libsystemd/sd-id128/id128-util.c +++ b/src/libsystemd/sd-id128/id128-util.c @@ -163,7 +163,7 @@ int id128_write_fd(int fd, Id128Flag f, sd_id128_t id) { } buffer[sz - 1] = '\n'; - r = loop_write(fd, buffer, sz, false); + r = loop_write(fd, buffer, sz); if (r < 0) return r; diff --git a/src/libsystemd/sd-journal/journal-send.c b/src/libsystemd/sd-journal/journal-send.c index 4380a21f7d0..784c7e5fb1a 100644 --- a/src/libsystemd/sd-journal/journal-send.c +++ b/src/libsystemd/sd-journal/journal-send.c @@ -438,7 +438,7 @@ _public_ int sd_journal_stream_fd(const char *identifier, int priority, int leve header[l++] = '0'; header[l++] = '\n'; - r = loop_write(fd, header, l, false); + r = loop_write(fd, header, l); if (r < 0) return r; diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 9e74ead8d58..3674f6b023b 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -2478,7 +2478,7 @@ static int setup_credentials(const char *root) { if (fd < 0) return log_error_errno(errno, "Failed to create credential file %s: %m", j); - r = loop_write(fd, arg_credentials[i].data, arg_credentials[i].size, /* do_poll= */ false); + r = loop_write(fd, arg_credentials[i].data, arg_credentials[i].size); if (r < 0) return log_error_errno(r, "Failed to write credential to file %s: %m", j); diff --git a/src/partition/repart.c b/src/partition/repart.c index b6fe9ef79ee..9325b321005 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -4166,7 +4166,7 @@ static int partition_format_verity_sig(Context *context, Partition *p) { if (lseek(whole_fd, p->offset, SEEK_SET) == (off_t) -1) return log_error_errno(errno, "Failed to seek to partition %s offset: %m", strna(hint)); - r = loop_write(whole_fd, text, p->new_size, /*do_poll=*/ false); + r = loop_write(whole_fd, text, p->new_size); if (r < 0) return log_error_errno(r, "Failed to write verity signature to partition %s: %m", strna(hint)); diff --git a/src/random-seed/random-seed.c b/src/random-seed/random-seed.c index 242fc190f9a..25d4d3f584c 100644 --- a/src/random-seed/random-seed.c +++ b/src/random-seed/random-seed.c @@ -286,7 +286,7 @@ static int save_seed_file( memcpy((uint8_t *)buf + k - l, hash, l); } - r = loop_write(seed_fd, buf, (size_t) k, false); + r = loop_write(seed_fd, buf, (size_t) k); if (r < 0) return log_error_errno(r, "Failed to write new random seed file: %m"); diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index 92a191ee60b..416130b9cc6 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -181,7 +181,7 @@ static int backspace_chars(int ttyfd, size_t p) { for (size_t i = 0; i < p; i++) memcpy(buf + 3 * i, "\b \b", 3); - return loop_write(ttyfd, buf, 3*p, false); + return loop_write(ttyfd, buf, 3 * p); } static int backspace_string(int ttyfd, const char *str) { @@ -252,7 +252,7 @@ int ask_password_plymouth( if (!packet) return -ENOMEM; - r = loop_write(fd, packet, n + 1, true); + r = loop_write_full(fd, packet, n + 1, USEC_INFINITY); if (r < 0) return r; @@ -311,7 +311,7 @@ int ask_password_plymouth( if (asprintf(&packet, "*\002%c%s%n", (int) (strlen(message) + 1), message, &n) < 0) return -ENOMEM; - r = loop_write(fd, packet, n+1, true); + r = loop_write_full(fd, packet, n + 1, USEC_INFINITY); if (r < 0) return r; @@ -429,20 +429,21 @@ int ask_password_tty( use_color = colors_enabled(); if (use_color) - (void) loop_write(ttyfd, ANSI_HIGHLIGHT, SIZE_MAX, false); + (void) loop_write(ttyfd, ANSI_HIGHLIGHT, SIZE_MAX); - (void) loop_write(ttyfd, message, SIZE_MAX, false); - (void) loop_write(ttyfd, " ", 1, false); + (void) loop_write(ttyfd, message, SIZE_MAX); + (void) loop_write(ttyfd, " ", 1); if (!FLAGS_SET(flags, ASK_PASSWORD_SILENT) && !FLAGS_SET(flags, ASK_PASSWORD_ECHO)) { if (use_color) - (void) loop_write(ttyfd, ansi_grey(), SIZE_MAX, false); - (void) loop_write(ttyfd, PRESS_TAB, SIZE_MAX, false); + (void) loop_write(ttyfd, ansi_grey(), SIZE_MAX); + + (void) loop_write(ttyfd, PRESS_TAB, SIZE_MAX); press_tab_visible = true; } if (use_color) - (void) loop_write(ttyfd, ANSI_NORMAL, SIZE_MAX, false); + (void) loop_write(ttyfd, ANSI_NORMAL, SIZE_MAX); new_termios = old_termios; new_termios.c_lflag &= ~(ICANON|ECHO); @@ -527,7 +528,7 @@ int ask_password_tty( if (c == 4) { /* C-d also known as EOT */ if (ttyfd >= 0) - (void) loop_write(ttyfd, SKIPPED, SIZE_MAX, false); + (void) loop_write(ttyfd, SKIPPED, SIZE_MAX); goto skipped; } @@ -577,10 +578,10 @@ int ask_password_tty( * first key (and only as first key), or ... */ if (ttyfd >= 0) - (void) loop_write(ttyfd, NO_ECHO, SIZE_MAX, false); + (void) loop_write(ttyfd, NO_ECHO, SIZE_MAX); } else if (ttyfd >= 0) - (void) loop_write(ttyfd, "\a", 1, false); + (void) loop_write(ttyfd, "\a", 1); } else if (c == '\t' && !FLAGS_SET(flags, ASK_PASSWORD_SILENT)) { @@ -590,13 +591,13 @@ int ask_password_tty( /* ... or by pressing TAB at any time. */ if (ttyfd >= 0) - (void) loop_write(ttyfd, NO_ECHO, SIZE_MAX, false); + (void) loop_write(ttyfd, NO_ECHO, SIZE_MAX); } else if (p >= sizeof(passphrase)-1) { /* Reached the size limit */ if (ttyfd >= 0) - (void) loop_write(ttyfd, "\a", 1, false); + (void) loop_write(ttyfd, "\a", 1); } else { passphrase[p++] = c; @@ -606,13 +607,11 @@ int ask_password_tty( n = utf8_encoded_valid_unichar(passphrase + codepoint, SIZE_MAX); if (n >= 0) { if (FLAGS_SET(flags, ASK_PASSWORD_ECHO)) - (void) loop_write(ttyfd, passphrase + codepoint, n, false); + (void) loop_write(ttyfd, passphrase + codepoint, n); else - (void) loop_write( - ttyfd, - special_glyph(SPECIAL_GLYPH_BULLET), - SIZE_MAX, - false); + (void) loop_write(ttyfd, + special_glyph(SPECIAL_GLYPH_BULLET), + SIZE_MAX); codepoint = p; } } @@ -644,7 +643,7 @@ skipped: finish: if (ttyfd >= 0 && reset_tty) { - (void) loop_write(ttyfd, "\n", 1, false); + (void) loop_write(ttyfd, "\n", 1); (void) tcsetattr(ttyfd, TCSADRAIN, &old_termios); } diff --git a/src/shared/creds-util.c b/src/shared/creds-util.c index 8a5240e5f19..0941826970b 100644 --- a/src/shared/creds-util.c +++ b/src/shared/creds-util.c @@ -382,7 +382,7 @@ static int make_credential_host_secret( if (r < 0) goto fail; - r = loop_write(fd, &buf, sizeof(buf), false); + r = loop_write(fd, &buf, sizeof(buf)); if (r < 0) goto fail; diff --git a/src/shared/data-fd-util.c b/src/shared/data-fd-util.c index 86baf9bfa1a..2fac0a9f446 100644 --- a/src/shared/data-fd-util.c +++ b/src/shared/data-fd-util.c @@ -275,7 +275,7 @@ int copy_data_fd(int fd) { /* If there were remaining bytes (i.e. read into memory, but not written out yet) from the * failed copy operation, let's flush them out next. */ - r = loop_write(tmp_fd, remains, remains_size, false); + r = loop_write(tmp_fd, remains, remains_size); if (r < 0) return r; } @@ -318,7 +318,7 @@ int copy_data_fd(int fd) { if (remains_size > 0) { /* Then, copy in any read but not yet written bytes. */ - r = loop_write(tmp_fd, remains, remains_size, false); + r = loop_write(tmp_fd, remains, remains_size); if (r < 0) return r; } diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 2d1952de798..4e0d61fbc2f 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -3348,7 +3348,7 @@ int dissected_image_acquire_metadata(DissectedImage *m, DissectImageFlags extra_ if (r < 0) fd = r; else { - r = loop_write(fds[2*k+1], &class, sizeof(class), false); + r = loop_write(fds[2*k+1], &class, sizeof(class)); if (r < 0) goto inner_fail; /* Propagate the error to the parent */ } @@ -3374,7 +3374,7 @@ int dissected_image_acquire_metadata(DissectedImage *m, DissectImageFlags extra_ } } - r = loop_write(fds[2*k+1], &found, sizeof(found), false); + r = loop_write(fds[2*k+1], &found, sizeof(found)); if (r < 0) goto inner_fail; diff --git a/src/shared/elf-util.c b/src/shared/elf-util.c index 7428152faa3..57a1bb9daa0 100644 --- a/src/shared/elf-util.c +++ b/src/shared/elf-util.c @@ -826,7 +826,7 @@ int parse_elf_object(int fd, const char *executable, bool fork_disable_dump, cha * Failure is ignored, because partial output is still useful. */ (void) fcntl(return_pipe[1], F_SETPIPE_SZ, len); - r = loop_write(return_pipe[1], buf, len, false); + r = loop_write(return_pipe[1], buf, len); if (r == -EAGAIN) log_warning("Write failed, backtrace will be truncated."); else if (r < 0) diff --git a/src/shared/machine-id-setup.c b/src/shared/machine-id-setup.c index 6090231374e..7263b6a204e 100644 --- a/src/shared/machine-id-setup.c +++ b/src/shared/machine-id-setup.c @@ -162,7 +162,7 @@ int machine_id_setup(const char *root, bool force_transient, sd_id128_t machine_ * * Otherwise write the machine-id directly to disk. */ if (force_transient) { - r = loop_write(fd, "uninitialized\n", SIZE_MAX, false); + r = loop_write(fd, "uninitialized\n", SIZE_MAX); if (r < 0) return log_error_errno(r, "Failed to write uninitialized %s: %m", etc_machine_id); diff --git a/src/shared/pager.c b/src/shared/pager.c index 7bede85752f..2cd9a353e33 100644 --- a/src/shared/pager.c +++ b/src/shared/pager.c @@ -204,7 +204,7 @@ void pager_open(PagerFlags flags) { * secure mode. Thus, start the pager specified through * envvars only when $SYSTEMD_PAGERSECURE was explicitly set * as well. */ - r = loop_write(exe_name_pipe[1], pager_args[0], strlen(pager_args[0]) + 1, false); + r = loop_write(exe_name_pipe[1], pager_args[0], strlen(pager_args[0]) + 1); if (r < 0) { log_error_errno(r, "Failed to write pager name to socket: %m"); _exit(EXIT_FAILURE); @@ -225,7 +225,7 @@ void pager_open(PagerFlags flags) { if (use_secure_mode && !STR_IN_SET(pagers[i], "less", "(built-in)")) continue; - r = loop_write(exe_name_pipe[1], pagers[i], strlen(pagers[i]) + 1, false); + r = loop_write(exe_name_pipe[1], pagers[i], strlen(pagers[i]) + 1); if (r < 0) { log_error_errno(r, "Failed to write pager name to socket: %m"); _exit(EXIT_FAILURE); diff --git a/src/shared/tpm2-util.c b/src/shared/tpm2-util.c index a57841fab4b..1181d73743b 100644 --- a/src/shared/tpm2-util.c +++ b/src/shared/tpm2-util.c @@ -4433,7 +4433,7 @@ static int tpm2_userspace_log( if (lseek(fd, 0, SEEK_END) == (off_t) -1) return log_error_errno(errno, "Failed to seek to end of JSON log: %m"); - r = loop_write(fd, f, SIZE_MAX, /* do_poll= */ false); + r = loop_write(fd, f, SIZE_MAX); if (r < 0) return log_error_errno(r, "Failed to write JSON data to log: %m"); diff --git a/src/systemctl/systemctl-sysv-compat.c b/src/systemctl/systemctl-sysv-compat.c index d55525943eb..37fc6347fe4 100644 --- a/src/systemctl/systemctl-sysv-compat.c +++ b/src/systemctl/systemctl-sysv-compat.c @@ -47,7 +47,7 @@ int talk_initctl(char rl) { .runlevel = rl, }; - r = loop_write(fd, &request, sizeof(request), false); + r = loop_write(fd, &request, sizeof(request)); if (r < 0) return log_error_errno(r, "Failed to write to %s: %m", path); diff --git a/src/test/test-copy.c b/src/test/test-copy.c index 06fa05d8fae..a46dd309bdf 100644 --- a/src/test/test-copy.c +++ b/src/test/test-copy.c @@ -470,10 +470,10 @@ TEST_RET(copy_holes_with_gaps) { return log_tests_skipped("Filesystem doesn't support hole punching"); assert_se(lseek(fd, blksz, SEEK_CUR) >= 0); - assert_se(loop_write(fd, buf, blksz, 0) >= 0); - assert_se(loop_write(fd, buf, blksz, 0) >= 0); + assert_se(loop_write(fd, buf, blksz) >= 0); + assert_se(loop_write(fd, buf, blksz) >= 0); assert_se(lseek(fd, 2 * blksz, SEEK_CUR) >= 0); - assert_se(loop_write(fd, buf, blksz, 0) >= 0); + assert_se(loop_write(fd, buf, blksz) >= 0); assert_se(lseek(fd, 0, SEEK_SET) >= 0); assert_se(fsync(fd) >= 0); diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index db2d61dbda9..564b505e76b 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -1625,7 +1625,7 @@ static int write_argument_data(Item *i, int fd, const char *path) { log_debug("Writing to \"%s\".", path); - r = loop_write(fd, item_binary_argument(i), item_binary_argument_size(i), /* do_poll= */ false); + r = loop_write(fd, item_binary_argument(i), item_binary_argument_size(i)); if (r < 0) return log_error_errno(r, "Failed to write file \"%s\": %m", path); diff --git a/src/udev/udev-worker.c b/src/udev/udev-worker.c index 996406a142d..53722b21bd6 100644 --- a/src/udev/udev-worker.c +++ b/src/udev/udev-worker.c @@ -277,7 +277,7 @@ static int worker_send_result(UdevWorker *worker, EventResult result) { assert(worker); assert(worker->pipe_fd >= 0); - return loop_write(worker->pipe_fd, &result, sizeof(result), /* do_poll = */ false); + return loop_write(worker->pipe_fd, &result, sizeof(result)); } static int worker_device_monitor_handler(sd_device_monitor *monitor, sd_device *dev, void *userdata) { diff --git a/src/vconsole/vconsole-setup.c b/src/vconsole/vconsole-setup.c index 17b0f9abfad..4aed1b5872c 100644 --- a/src/vconsole/vconsole-setup.c +++ b/src/vconsole/vconsole-setup.c @@ -242,7 +242,7 @@ static int toggle_utf8_vc(const char *name, int fd, bool utf8) { if (r < 0) return log_warning_errno(errno, "Failed to %s UTF-8 kbdmode on %s: %m", enable_disable(utf8), name); - r = loop_write(fd, utf8 ? "\033%G" : "\033%@", SIZE_MAX, false); + r = loop_write(fd, utf8 ? "\033%G" : "\033%@", SIZE_MAX); if (r < 0) return log_warning_errno(r, "Failed to %s UTF-8 term processing on %s: %m", enable_disable(utf8), name);