diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-10-18 06:52:47 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-10-19 11:31:44 +0200 |
commit | 86cbbc6d052bc3cc97aa2ece58603a9939f9ee6a (patch) | |
tree | 6186d2df19cd787bdc5530462ee063fe8cff8cbc /src | |
parent | fuzz: unify logging setup (diff) | |
download | systemd-86cbbc6d052bc3cc97aa2ece58603a9939f9ee6a.tar.xz systemd-86cbbc6d052bc3cc97aa2ece58603a9939f9ee6a.zip |
tree-wide: check if return value of lseek() and friends is negative
We usually check return value of syscalls or glibc functions by it is
negative or not, something like that `if (stat(path, &st) < 0)`.
Let's also use the same style for lseek() and friends even the type of
their return value is off_t.
Note, fseeko() returns int, instead of off_t.
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/io-util.c | 2 | ||||
-rw-r--r-- | src/boot/bootctl-install.c | 2 | ||||
-rw-r--r-- | src/core/execute.c | 2 | ||||
-rw-r--r-- | src/core/main.c | 2 | ||||
-rw-r--r-- | src/coredump/coredump.c | 6 | ||||
-rw-r--r-- | src/home/homed-home.c | 2 | ||||
-rw-r--r-- | src/import/import-raw.c | 4 | ||||
-rw-r--r-- | src/import/pull-job.c | 2 | ||||
-rw-r--r-- | src/import/pull-raw.c | 2 | ||||
-rw-r--r-- | src/journal-remote/journal-gatewayd.c | 4 | ||||
-rw-r--r-- | src/machine/machined-dbus.c | 2 | ||||
-rw-r--r-- | src/partition/repart.c | 8 | ||||
-rw-r--r-- | src/shared/elf-util.c | 4 | ||||
-rw-r--r-- | src/shared/machine-id-setup.c | 2 | ||||
-rw-r--r-- | src/shared/tpm2-util.c | 2 |
15 files changed, 23 insertions, 23 deletions
diff --git a/src/basic/io-util.c b/src/basic/io-util.c index 25831e47dc..15eca4e3a8 100644 --- a/src/basic/io-util.c +++ b/src/basic/io-util.c @@ -283,7 +283,7 @@ ssize_t sparse_write(int fd, const void *p, size_t sz, size_t run_length) { return -EIO; } - if (lseek(fd, n, SEEK_CUR) == (off_t) -1) + if (lseek(fd, n, SEEK_CUR) < 0) return -errno; q += n; diff --git a/src/boot/bootctl-install.c b/src/boot/bootctl-install.c index e6f66deeab..fb7cda7df5 100644 --- a/src/boot/bootctl-install.c +++ b/src/boot/bootctl-install.c @@ -233,7 +233,7 @@ static int copy_file_with_version_check(const char *from, const char *to, bool f if (r < 0) return r; - if (lseek(fd_from, 0, SEEK_SET) == (off_t) -1) + if (lseek(fd_from, 0, SEEK_SET) < 0) return log_error_errno(errno, "Failed to seek in \"%s\": %m", from); fd_to = safe_close(fd_to); diff --git a/src/core/execute.c b/src/core/execute.c index 46fb8805b3..13c406aa1e 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -405,7 +405,7 @@ int exec_spawn(Unit *unit, if (r < 0) return log_unit_error_errno(unit, r, "Failed to serialize parameters: %m"); - if (fseeko(f, 0, SEEK_SET) == (off_t) -1) + if (fseeko(f, 0, SEEK_SET) < 0) return log_unit_error_errno(unit, errno, "Failed to reseek on serialization stream: %m"); r = fd_cloexec(fileno(f), false); diff --git a/src/core/main.c b/src/core/main.c index cbcf3ddeea..cfa29f3a58 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1108,7 +1108,7 @@ static int prepare_reexecute( if (r < 0) return r; - if (fseeko(f, 0, SEEK_SET) == (off_t) -1) + if (fseeko(f, 0, SEEK_SET) < 0) return log_error_errno(errno, "Failed to rewind serialization fd: %m"); r = fd_cloexec(fileno(f), false); diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c index 1962512c67..151c5eb91a 100644 --- a/src/coredump/coredump.c +++ b/src/coredump/coredump.c @@ -531,7 +531,7 @@ static int save_external_coredump( _cleanup_close_ int fd_compressed = -EBADF; uint64_t uncompressed_size = 0; - if (lseek(fd, 0, SEEK_SET) == (off_t) -1) + if (lseek(fd, 0, SEEK_SET) < 0) return log_error_errno(errno, "Failed to seek on coredump %s: %m", fn); fn_compressed = strjoin(fn, default_compression_extension()); @@ -595,7 +595,7 @@ static int save_external_coredump( if (fstat(fd, &st) < 0) return log_error_errno(errno, "Failed to fstat core file %s: %m", coredump_tmpfile_name(tmp)); - if (lseek(fd, 0, SEEK_SET) == (off_t) -1) + if (lseek(fd, 0, SEEK_SET) < 0) return log_error_errno(errno, "Failed to seek on coredump %s: %m", fn); *ret_filename = TAKE_PTR(fn); @@ -614,7 +614,7 @@ static int allocate_journal_field(int fd, size_t size, char **ret, size_t *ret_s assert(ret); assert(ret_size); - if (lseek(fd, 0, SEEK_SET) == (off_t) -1) + if (lseek(fd, 0, SEEK_SET) < 0) return log_warning_errno(errno, "Failed to seek: %m"); field = malloc(9 + size); diff --git a/src/home/homed-home.c b/src/home/homed-home.c index 206f6480ac..749670f94b 100644 --- a/src/home/homed-home.c +++ b/src/home/homed-home.c @@ -519,7 +519,7 @@ static int home_parse_worker_stdout(int _fd, UserRecord **ret) { return 0; } - if (lseek(fd, SEEK_SET, 0) == (off_t) -1) + if (lseek(fd, SEEK_SET, 0) < 0) return log_error_errno(errno, "Failed to seek to beginning of memfd: %m"); f = take_fdopen(&fd, "r"); diff --git a/src/import/import-raw.c b/src/import/import-raw.c index feb6ac1bdd..2db3198ba6 100644 --- a/src/import/import-raw.c +++ b/src/import/import-raw.c @@ -303,7 +303,7 @@ static int raw_import_open_disk(RawImport *i) { "Target file is not a regular file or block device"); if (i->offset != UINT64_MAX) { - if (lseek(i->output_fd, i->offset, SEEK_SET) == (off_t) -1) + if (lseek(i->output_fd, i->offset, SEEK_SET) < 0) return log_error_errno(errno, "Failed to seek to offset: %m"); } @@ -328,7 +328,7 @@ static int raw_import_try_reflink(RawImport *i) { return 0; p = lseek(i->input_fd, 0, SEEK_CUR); - if (p == (off_t) -1) + if (p < 0) return log_error_errno(errno, "Failed to read file offset of input file: %m"); /* Let's only try a btrfs reflink, if we are reading from the beginning of the file */ diff --git a/src/import/pull-job.c b/src/import/pull-job.c index d05bf3cd49..bed7e64030 100644 --- a/src/import/pull-job.c +++ b/src/import/pull-job.c @@ -415,7 +415,7 @@ static int pull_job_open_disk(PullJob *j) { return log_error_errno(errno, "Failed to stat disk file: %m"); if (j->offset != UINT64_MAX) { - if (lseek(j->disk_fd, j->offset, SEEK_SET) == (off_t) -1) + if (lseek(j->disk_fd, j->offset, SEEK_SET) < 0) return log_error_errno(errno, "Failed to seek on file descriptor: %m"); } } diff --git a/src/import/pull-raw.c b/src/import/pull-raw.c index 3befa96a04..e96be4dd7d 100644 --- a/src/import/pull-raw.c +++ b/src/import/pull-raw.c @@ -370,7 +370,7 @@ static int raw_pull_make_local_copy(RawPull *i) { assert(i->raw_job->disk_fd >= 0); assert(i->offset == UINT64_MAX); - if (lseek(i->raw_job->disk_fd, SEEK_SET, 0) == (off_t) -1) + if (lseek(i->raw_job->disk_fd, SEEK_SET, 0) < 0) return log_error_errno(errno, "Failed to seek to beginning of vendor image: %m"); } diff --git a/src/journal-remote/journal-gatewayd.c b/src/journal-remote/journal-gatewayd.c index 980b98137e..09194710cb 100644 --- a/src/journal-remote/journal-gatewayd.c +++ b/src/journal-remote/journal-gatewayd.c @@ -233,7 +233,7 @@ static ssize_t request_reader_entries( } sz = ftello(m->tmp); - if (sz == (off_t) -1) { + if (sz < 0) { log_error_errno(errno, "Failed to retrieve file position: %m"); return MHD_CONTENT_READER_END_WITH_ERROR; } @@ -582,7 +582,7 @@ static ssize_t request_reader_fields( } sz = ftello(m->tmp); - if (sz == (off_t) -1) { + if (sz < 0) { log_error_errno(errno, "Failed to retrieve file position: %m"); return MHD_CONTENT_READER_END_WITH_ERROR; } diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c index 979eb3cee7..a12eb516cc 100644 --- a/src/machine/machined-dbus.c +++ b/src/machine/machined-dbus.c @@ -613,7 +613,7 @@ static int clean_pool_done(Operation *operation, int ret, sd_bus_error *error) { assert(operation); assert(operation->extra_fd >= 0); - if (lseek(operation->extra_fd, 0, SEEK_SET) == (off_t) -1) + if (lseek(operation->extra_fd, 0, SEEK_SET) < 0) return -errno; f = take_fdopen(&operation->extra_fd, "r"); diff --git a/src/partition/repart.c b/src/partition/repart.c index 20c30c1e15..f5d41eeae1 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -3562,7 +3562,7 @@ static int partition_target_prepare( }; if (!need_path) { - if (lseek(whole_fd, p->offset, SEEK_SET) == (off_t) -1) + if (lseek(whole_fd, p->offset, SEEK_SET) < 0) return log_error_errno(errno, "Failed to seek to partition offset: %m"); t->whole_fd = whole_fd; @@ -3638,10 +3638,10 @@ static int partition_target_sync(Context *context, Partition *p, PartitionTarget } else if (t->fd >= 0) { struct stat st; - if (lseek(whole_fd, p->offset, SEEK_SET) == (off_t) -1) + if (lseek(whole_fd, p->offset, SEEK_SET) < 0) return log_error_errno(errno, "Failed to seek to partition offset: %m"); - if (lseek(t->fd, 0, SEEK_SET) == (off_t) -1) + if (lseek(t->fd, 0, SEEK_SET) < 0) return log_error_errno(errno, "Failed to seek to start of temporary file: %m"); if (fstat(t->fd, &st) < 0) @@ -4200,7 +4200,7 @@ static int partition_format_verity_sig(Context *context, Partition *p) { if (r < 0) return log_error_errno(r, "Failed to pad string to %s", FORMAT_BYTES(p->new_size)); - if (lseek(whole_fd, p->offset, SEEK_SET) == (off_t) -1) + if (lseek(whole_fd, p->offset, SEEK_SET) < 0) return log_error_errno(errno, "Failed to seek to partition %s offset: %m", strna(hint)); r = loop_write(whole_fd, text, p->new_size); diff --git a/src/shared/elf-util.c b/src/shared/elf-util.c index 57a1bb9daa..5a4d3bbb50 100644 --- a/src/shared/elf-util.c +++ b/src/shared/elf-util.c @@ -588,7 +588,7 @@ static int parse_core(int fd, const char *executable, char **ret, JsonVariant ** assert(fd >= 0); - if (lseek(fd, 0, SEEK_SET) == (off_t) -1) + if (lseek(fd, 0, SEEK_SET) < 0) return log_warning_errno(errno, "Failed to seek to beginning of the core file: %m"); if (ret && !memstream_init(&c.m)) @@ -644,7 +644,7 @@ static int parse_elf(int fd, const char *executable, char **ret, JsonVariant **r assert(fd >= 0); - if (lseek(fd, 0, SEEK_SET) == (off_t) -1) + if (lseek(fd, 0, SEEK_SET) < 0) return log_warning_errno(errno, "Failed to seek to beginning of the ELF file: %m"); if (ret && !memstream_init(&c.m)) diff --git a/src/shared/machine-id-setup.c b/src/shared/machine-id-setup.c index 7263b6a204..d6aa667ada 100644 --- a/src/shared/machine-id-setup.c +++ b/src/shared/machine-id-setup.c @@ -151,7 +151,7 @@ int machine_id_setup(const char *root, bool force_transient, sd_id128_t machine_ } if (writable) { - if (lseek(fd, 0, SEEK_SET) == (off_t) -1) + if (lseek(fd, 0, SEEK_SET) < 0) return log_error_errno(errno, "Failed to seek %s: %m", etc_machine_id); if (ftruncate(fd, 0) < 0) diff --git a/src/shared/tpm2-util.c b/src/shared/tpm2-util.c index bb7928bbd7..46e5ec57e5 100644 --- a/src/shared/tpm2-util.c +++ b/src/shared/tpm2-util.c @@ -4586,7 +4586,7 @@ static int tpm2_userspace_log( if (r < 0) return log_debug_errno(r, "Failed to format JSON: %m"); - if (lseek(fd, 0, SEEK_END) == (off_t) -1) + if (lseek(fd, 0, SEEK_END) < 0) return log_debug_errno(errno, "Failed to seek to end of JSON log: %m"); r = loop_write(fd, f, SIZE_MAX); |