all: assert that native errno numbers are positive

Use the NM_ERRNO_NATIVE() macro that asserts that these errno numbers are
indeed positive. Using the macro also serves as a documentation of what
the meaning of these numbers is.

That is often not obvious, whether we have an nm_errno(), an nm_errno_native()
(from <errno.h>), or another error number (e.g. WaitForNlResponseResult). This
situation already improved by merging netlink error codes (nle),
NMPlatformError enum and <errno.h> as nm_errno(). But we still must
always be careful about not to mix error codes from different
domains or transform them appropriately (like nm_errno_from_native()).
This commit is contained in:
Thomas Haller
2019-01-31 16:53:45 +01:00
parent 67130e6706
commit 4d9918aac2
5 changed files with 17 additions and 19 deletions

View File

@@ -84,7 +84,7 @@ socket_handle_init (SocketHandle *shandle, int ifindex)
shandle->fd = socket (PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (shandle->fd < 0) {
shandle->ifindex = 0;
return -errno;
return -NM_ERRNO_NATIVE (errno);
}
shandle->ifindex = ifindex;
@@ -158,7 +158,7 @@ ethtool_call_handle (SocketHandle *shandle, gpointer edata)
_ethtool_data_to_string (edata, sbuf, sizeof (sbuf)),
shandle->ifname,
strerror (errsv));
return -errsv;
return -NM_ERRNO_NATIVE (errsv);
}
nm_log_trace (LOGD_PLATFORM, "ethtool[%d]: %s, %s: success",