diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-12-19 13:07:42 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-12-19 15:00:57 +0100 |
commit | 254d1313ae5a69c08c9b93032aaaf3d6083cfc07 (patch) | |
tree | 067102a36abe6bf597c26a42d79018a1060c9007 /src/test/test-fs-util.c | |
parent | sd-event: never pass negative errnos as signalfd to signalfd (diff) | |
download | systemd-254d1313ae5a69c08c9b93032aaaf3d6083cfc07.tar.xz systemd-254d1313ae5a69c08c9b93032aaaf3d6083cfc07.zip |
tree-wide: use -EBADF for fd initialization
-1 was used everywhere, but -EBADF or -EBADFD started being used in various
places. Let's make things consistent in the new style.
Note that there are two candidates:
EBADF 9 Bad file descriptor
EBADFD 77 File descriptor in bad state
Since we're initializating the fd, we're just assigning a value that means
"no fd yet", so it's just a bad file descriptor, and the first errno fits
better. If instead we had a valid file descriptor that became invalid because
of some operation or state change, the other errno would fit better.
In some places, initialization is dropped if unnecessary.
Diffstat (limited to 'src/test/test-fs-util.c')
-rw-r--r-- | src/test/test-fs-util.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c index 69f6303990..38299ce729 100644 --- a/src/test/test-fs-util.c +++ b/src/test/test-fs-util.c @@ -28,7 +28,7 @@ static const char *arg_test_dir = NULL; TEST(chase_symlinks) { _cleanup_free_ char *result = NULL, *pwd = NULL; - _cleanup_close_ int pfd = -1; + _cleanup_close_ int pfd = -EBADF; char *temp; const char *top, *p, *pslash, *q, *qslash; struct stat st; @@ -316,7 +316,7 @@ TEST(chase_symlinks) { r = chase_symlinks(p, NULL, 0, NULL, &pfd); if (r != -ENOENT && sd_id128_get_machine(NULL) >= 0) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; sd_id128_t a, b; assert_se(pfd >= 0); @@ -553,7 +553,7 @@ TEST(dot_or_dot_dot) { TEST(access_fd) { _cleanup_(rmdir_and_freep) char *p = NULL; - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; const char *a; a = strjoina(arg_test_dir ?: "/tmp", "/access-fd.XXXXXX"); @@ -679,7 +679,7 @@ TEST(touch_file) { TEST(unlinkat_deallocate) { _cleanup_free_ char *p = NULL; - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; struct stat st; assert_se(tempfn_random_child(arg_test_dir, "unlink-deallocation", &p) >= 0); @@ -704,7 +704,7 @@ TEST(unlinkat_deallocate) { } TEST(fsync_directory_of_file) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; fd = open_tmpfile_unlinkable(arg_test_dir, O_RDWR); assert_se(fd >= 0); @@ -821,7 +821,7 @@ TEST(chmod_and_chown) { } static void create_binary_file(const char *p, const void *data, size_t l) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; fd = open(p, O_CREAT|O_WRONLY|O_EXCL|O_CLOEXEC, 0600); assert_se(fd >= 0); @@ -961,7 +961,7 @@ TEST(parse_cifs_service) { } TEST(open_mkdir_at) { - _cleanup_close_ int fd = -1, subdir_fd = -1, subsubdir_fd = -1; + _cleanup_close_ int fd = -EBADF, subdir_fd = -EBADF, subsubdir_fd = -EBADF; _cleanup_(rm_rf_physical_and_freep) char *t = NULL; assert_se(open_mkdir_at(AT_FDCWD, "/proc", O_EXCL|O_CLOEXEC, 0) == -EEXIST); @@ -1005,7 +1005,7 @@ TEST(open_mkdir_at) { TEST(openat_report_new) { _cleanup_free_ char *j = NULL; _cleanup_(rm_rf_physical_and_freep) char *d = NULL; - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; bool b; assert_se(mkdtemp_malloc(NULL, &d) >= 0); |