summaryrefslogtreecommitdiffstats
path: root/src/resolve
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-12-19 13:07:42 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-12-19 15:00:57 +0100
commit254d1313ae5a69c08c9b93032aaaf3d6083cfc07 (patch)
tree067102a36abe6bf597c26a42d79018a1060c9007 /src/resolve
parentsd-event: never pass negative errnos as signalfd to signalfd (diff)
downloadsystemd-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/resolve')
-rw-r--r--src/resolve/resolved-dns-scope.c2
-rw-r--r--src/resolve/resolved-dns-stream.c2
-rw-r--r--src/resolve/resolved-dns-stub.c4
-rw-r--r--src/resolve/resolved-dns-transaction.c6
-rw-r--r--src/resolve/resolved-manager.c14
-rw-r--r--src/resolve/test-resolved-stream.c8
6 files changed, 18 insertions, 18 deletions
diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c
index 635763954b..0c062efc98 100644
--- a/src/resolve/resolved-dns-scope.c
+++ b/src/resolve/resolved-dns-scope.c
@@ -351,7 +351,7 @@ static int dns_scope_socket(
uint16_t port,
union sockaddr_union *ret_socket_address) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
union sockaddr_union sa;
socklen_t salen;
int r, ifindex;
diff --git a/src/resolve/resolved-dns-stream.c b/src/resolve/resolved-dns-stream.c
index 95fbb56cd7..0a10a0d17e 100644
--- a/src/resolve/resolved-dns-stream.c
+++ b/src/resolve/resolved-dns-stream.c
@@ -523,7 +523,7 @@ int dns_stream_new(
*s = (DnsStream) {
.n_ref = 1,
- .fd = -1,
+ .fd = -EBADF,
.protocol = protocol,
.type = type,
};
diff --git a/src/resolve/resolved-dns-stub.c b/src/resolve/resolved-dns-stub.c
index 8a8a0b19ee..facd95aeb8 100644
--- a/src/resolve/resolved-dns-stub.c
+++ b/src/resolve/resolved-dns-stub.c
@@ -1138,7 +1138,7 @@ static int manager_dns_stub_fd(
int type) {
sd_event_source **event_source;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
union sockaddr_union sa;
int r;
@@ -1225,7 +1225,7 @@ static int manager_dns_stub_fd(
static int manager_dns_stub_fd_extra(Manager *m, DnsStubListenerExtra *l, int type) {
_cleanup_free_ char *pretty = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
union sockaddr_union sa;
int r;
diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c
index 0212569fb0..8d76630adb 100644
--- a/src/resolve/resolved-dns-transaction.c
+++ b/src/resolve/resolved-dns-transaction.c
@@ -273,7 +273,7 @@ int dns_transaction_new(
return -ENOMEM;
*t = (DnsTransaction) {
- .dns_udp_fd = -1,
+ .dns_udp_fd = -EBADF,
.answer_source = _DNS_TRANSACTION_SOURCE_INVALID,
.answer_dnssec_result = _DNSSEC_RESULT_INVALID,
.answer_nsec_ttl = UINT32_MAX,
@@ -669,7 +669,7 @@ static uint16_t dns_transaction_port(DnsTransaction *t) {
static int dns_transaction_emit_tcp(DnsTransaction *t) {
usec_t stream_timeout_usec = DNS_STREAM_DEFAULT_TIMEOUT_USEC;
_cleanup_(dns_stream_unrefp) DnsStream *s = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
union sockaddr_union sa;
DnsStreamType type;
int r;
@@ -753,7 +753,7 @@ static int dns_transaction_emit_tcp(DnsTransaction *t) {
if (r < 0)
return r;
- fd = -1;
+ fd = -EBADF;
#if ENABLE_DNS_OVER_TLS
if (t->scope->protocol == DNS_PROTOCOL_DNS &&
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c
index 1c9048670b..6c6c98566f 100644
--- a/src/resolve/resolved-manager.c
+++ b/src/resolve/resolved-manager.c
@@ -554,13 +554,13 @@ int manager_new(Manager **ret) {
return -ENOMEM;
*m = (Manager) {
- .llmnr_ipv4_udp_fd = -1,
- .llmnr_ipv6_udp_fd = -1,
- .llmnr_ipv4_tcp_fd = -1,
- .llmnr_ipv6_tcp_fd = -1,
- .mdns_ipv4_fd = -1,
- .mdns_ipv6_fd = -1,
- .hostname_fd = -1,
+ .llmnr_ipv4_udp_fd = -EBADF,
+ .llmnr_ipv6_udp_fd = -EBADF,
+ .llmnr_ipv4_tcp_fd = -EBADF,
+ .llmnr_ipv6_tcp_fd = -EBADF,
+ .mdns_ipv4_fd = -EBADF,
+ .mdns_ipv6_fd = -EBADF,
+ .hostname_fd = -EBADF,
.llmnr_support = DEFAULT_LLMNR_MODE,
.mdns_support = DEFAULT_MDNS_MODE,
diff --git a/src/resolve/test-resolved-stream.c b/src/resolve/test-resolved-stream.c
index 96395ad27a..c708eb4da8 100644
--- a/src/resolve/test-resolved-stream.c
+++ b/src/resolve/test-resolved-stream.c
@@ -107,7 +107,7 @@ static void server_handle(int fd) {
}
static void *tcp_dns_server(void *p) {
- _cleanup_close_ int bindfd = -1, acceptfd = -1;
+ _cleanup_close_ int bindfd = -EBADF, acceptfd = -EBADF;
assert_se((bindfd = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0)) >= 0);
assert_se(setsockopt(bindfd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)) >= 0);
@@ -125,7 +125,7 @@ static void *tcp_dns_server(void *p) {
static void *tls_dns_server(void *p) {
pid_t openssl_pid;
int r;
- _cleanup_close_ int fd_server = -1, fd_tls = -1;
+ _cleanup_close_ int fd_server = -EBADF, fd_tls = -EBADF;
_cleanup_free_ char *cert_path = NULL, *key_path = NULL;
_cleanup_free_ char *bind_str = NULL;
@@ -213,7 +213,7 @@ static void test_dns_stream(bool tls) {
Manager manager = {};
_cleanup_(dns_stream_unrefp) DnsStream *stream = NULL;
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
- _cleanup_close_ int clientfd = -1;
+ _cleanup_close_ int clientfd = -EBADF;
int r;
void *(*server_entrypoint)(void *);
@@ -331,7 +331,7 @@ static void test_dns_stream(bool tls) {
}
static void try_isolate_network(void) {
- _cleanup_close_ int socket_fd = -1;
+ _cleanup_close_ int socket_fd = -EBADF;
int r;
/* First test if CLONE_NEWUSER/CLONE_NEWNET can actually work for us, i.e. we can open the namespaces