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-socket-util.c | |
parent | cbff793ffb280d9d11e5d7b1dc3964276491bee8 (diff) | |
download | systemd-254d1313ae5a69c08c9b93032aaaf3d6083cfc07.tar.gz |
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-socket-util.c')
-rw-r--r-- | src/test/test-socket-util.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/test/test-socket-util.c b/src/test/test-socket-util.c index cd1e374ec8..6456316aae 100644 --- a/src/test/test-socket-util.c +++ b/src/test/test-socket-util.c @@ -249,7 +249,7 @@ TEST(passfd_read) { /* Parent */ char buf[64]; struct iovec iov = IOVEC_INIT(buf, sizeof(buf)-1); - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd; pair[1] = safe_close(pair[1]); @@ -293,7 +293,7 @@ TEST(passfd_contents_read) { /* Parent */ char buf[64]; struct iovec iov = IOVEC_INIT(buf, sizeof(buf)-1); - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd; ssize_t k; pair[1] = safe_close(pair[1]); @@ -344,7 +344,7 @@ TEST(receive_nopassfd) { assert_se(streq(buf, wire_contents)); /* no fd passed here, confirm it was reset */ - assert_se(fd == -1); + assert_se(fd == -EBADF); } TEST(send_nodata_nofd) { @@ -418,7 +418,7 @@ TEST(send_emptydata) { } TEST(flush_accept) { - _cleanup_close_ int listen_stream = -1, listen_dgram = -1, listen_seqpacket = 1, connect_stream = -1, connect_dgram = -1, connect_seqpacket = -1; + _cleanup_close_ int listen_stream, listen_dgram, listen_seqpacket, connect_stream, connect_dgram, connect_seqpacket; static const union sockaddr_union sa = { .un.sun_family = AF_UNIX }; union sockaddr_union lsa; socklen_t l; @@ -488,7 +488,7 @@ TEST(sockaddr_un_set_path) { _cleanup_(unlink_and_freep) char *sh = NULL; _cleanup_free_ char *j = NULL; union sockaddr_union sa; - _cleanup_close_ int fd1 = -1, fd2 = -1, fd3 = -1; + _cleanup_close_ int fd1, fd2, fd3; assert_se(mkdtemp_malloc("/tmp/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaXXXXXX", &t) >= 0); assert_se(strlen(t) > SUN_PATH_LEN); |