aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-05-18 20:35:01 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-05-19 15:14:18 +0200
commit4aab839c90e4f390956cb777237c1acb115ebeae (patch)
treee7b1b7622549180ffb3c10992e220de2fa36926a /src/libsystemd
parentfix race between daemon-reload and other commands (diff)
downloadsystemd-4aab839c90e4f390956cb777237c1acb115ebeae.tar.gz
systemd-4aab839c90e4f390956cb777237c1acb115ebeae.tar.bz2
systemd-4aab839c90e4f390956cb777237c1acb115ebeae.zip
sd-resolve: tweak error assignment code a bit, use abs() and regular functions
Let's tweak the assignment of errors a bit, and automatically abs() errnos, similar to how log_error_errno() and friends does it. Macros are fine to use, but regular functions usually preferable if there's no reason to use macros, because they avoid multiple evaluation and suchlike. Hence, let's just use a regular funciton for assigning errors, instead of macros. Follow-up for #8993
Diffstat (limited to 'src/libsystemd')
-rw-r--r--src/libsystemd/sd-resolve/sd-resolve.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/libsystemd/sd-resolve/sd-resolve.c b/src/libsystemd/sd-resolve/sd-resolve.c
index ba0f15538..fcf4d2ef6 100644
--- a/src/libsystemd/sd-resolve/sd-resolve.c
+++ b/src/libsystemd/sd-resolve/sd-resolve.c
@@ -168,8 +168,13 @@ static void resolve_query_disconnect(sd_resolve_query *q);
#define RESOLVE_DONT_DESTROY(resolve) \
_cleanup_(sd_resolve_unrefp) _unused_ sd_resolve *_dont_destroy_##resolve = sd_resolve_ref(resolve)
-#define ASSIGN_ERRNO(q, val, error, h_error) \
- ({ (q)->ret = (val); (q)->_errno = (error); (q)->_h_errno = (h_error); })
+static void query_assign_errno(sd_resolve_query *q, int ret, int error, int h_error) {
+ assert(q);
+
+ q->ret = ret;
+ q->_errno = abs(error);
+ q->_h_errno = h_error;
+}
static int send_died(int out_fd) {
RHeader rh = {
@@ -767,7 +772,7 @@ static int handle_response(sd_resolve *resolve, const Packet *packet, size_t len
assert_return(length >= sizeof(AddrInfoResponse), -EBADMSG);
assert_return(q->type == REQUEST_ADDRINFO, -EBADMSG);
- ASSIGN_ERRNO(q, ai_resp->ret, ai_resp->_errno, ai_resp->_h_errno);
+ query_assign_errno(q, ai_resp->ret, ai_resp->_errno, ai_resp->_h_errno);
l = length - sizeof(AddrInfoResponse);
p = (const uint8_t*) resp + sizeof(AddrInfoResponse);
@@ -777,7 +782,7 @@ static int handle_response(sd_resolve *resolve, const Packet *packet, size_t len
r = unserialize_addrinfo(&p, &l, &ai);
if (r < 0) {
- ASSIGN_ERRNO(q, EAI_SYSTEM, -r, 0);
+ query_assign_errno(q, EAI_SYSTEM, r, 0);
freeaddrinfo(q->addrinfo);
q->addrinfo = NULL;
break;
@@ -803,23 +808,22 @@ static int handle_response(sd_resolve *resolve, const Packet *packet, size_t len
if (ni_resp->hostlen > DNS_HOSTNAME_MAX ||
ni_resp->servlen > DNS_HOSTNAME_MAX ||
sizeof(NameInfoResponse) + ni_resp->hostlen + ni_resp->servlen > length)
- ASSIGN_ERRNO(q, EAI_SYSTEM, EIO, 0);
-
+ query_assign_errno(q, EAI_SYSTEM, EIO, 0);
else {
- ASSIGN_ERRNO(q, ni_resp->ret, ni_resp->_errno, ni_resp->_h_errno);
+ query_assign_errno(q, ni_resp->ret, ni_resp->_errno, ni_resp->_h_errno);
if (ni_resp->hostlen > 0) {
q->host = strndup((const char*) ni_resp + sizeof(NameInfoResponse),
ni_resp->hostlen-1);
if (!q->host)
- ASSIGN_ERRNO(q, EAI_MEMORY, ENOMEM, 0);
+ query_assign_errno(q, EAI_MEMORY, ENOMEM, 0);
}
if (ni_resp->servlen > 0) {
q->serv = strndup((const char*) ni_resp + sizeof(NameInfoResponse) + ni_resp->hostlen,
ni_resp->servlen-1);
if (!q->serv)
- ASSIGN_ERRNO(q, EAI_MEMORY, ENOMEM, 0);
+ query_assign_errno(q, EAI_MEMORY, ENOMEM, 0);
}
}