io-util: introduce loop_write_full that takes a timeout

Also drop do_poll as the use case is covered
by timeout.
This commit is contained in:
Mike Yuan 2023-09-05 22:15:09 +08:00
parent 82b7bf8c1c
commit e22c60a9d5
No known key found for this signature in database
GPG key ID: 417471C0A40F58B3
34 changed files with 103 additions and 81 deletions

View file

@ -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;

View file

@ -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;

View file

@ -5,6 +5,7 @@
#include <stdio.h>
#include <unistd.h>
#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 */

View file

@ -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);

View file

@ -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;
}

View file

@ -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");

View file

@ -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");

View file

@ -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;

View file

@ -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;

View file

@ -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");

View file

@ -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");
}

View file

@ -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;

View file

@ -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;

View file

@ -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");
}

View file

@ -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");

View file

@ -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");

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -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));

View file

@ -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");

View file

@ -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);
}

View file

@ -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;

View file

@ -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;
}

View file

@ -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;

View file

@ -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)

View file

@ -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);

View file

@ -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);

View file

@ -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");

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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) {

View file

@ -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);