summaryrefslogtreecommitdiff
path: root/src/platform/nm-netlink.h
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-09-10 14:54:13 +0200
committerThomas Haller <thaller@redhat.com>2018-09-12 11:20:06 +0200
commit7943b2bb2e94717472adaed7f63b0b3c8260750c (patch)
treee6e9e223896e995be0c773b74739d92a43580da3 /src/platform/nm-netlink.h
parentb25e5625ac7629dcaf493014b327b7425eab01ac (diff)
platform/netlink: cleanup error number handling
Rename variables for the error number. Commonly the naming is: - errno: the error number from <errno.h> itself - errsv: a copy of errno - nlerr: a netlink error number - err: an error code, but not a errno/errsv and not a netlink error number. (cherry picked from commit f4de941d98d4329f652d419dc5fd47bc39700f44)
Diffstat (limited to 'src/platform/nm-netlink.h')
-rw-r--r--src/platform/nm-netlink.h48
1 files changed, 32 insertions, 16 deletions
diff --git a/src/platform/nm-netlink.h b/src/platform/nm-netlink.h
index 187685d824..1fccddb997 100644
--- a/src/platform/nm-netlink.h
+++ b/src/platform/nm-netlink.h
@@ -52,32 +52,48 @@
#endif
static inline int
-nl_errno (int err)
+nl_errno (int nlerr)
{
- /* the error codes from our netlink implementation are plain errno
- * extended with our own error in a particular range starting from
- * _NLE_BASE.
+ /* Normalizes an netlink error to be positive. Various API returns negative
+ * error codes, and this function converts the negative value to its
+ * positive.
*
- * However, often we encode errors as negative values. This function
- * normalizes the error and returns its positive value. */
- return err >= 0
- ? err
- : ((err == G_MININT) ? NLE_BUG : -err);
+ * It's very similar to nm_errno(), but not exactly. The difference is that
+ * nm_errno() is for plain errno, while nl_errno() is for netlink error numbers.
+ * Yes, netlink error number are ~almost~ the same as errno, except that a particular
+ * range (_NLE_BASE, _NLE_BASE_END) is reserved. The difference between the two
+ * functions is only how G_MININT is mapped.
+ *
+ * See also nl_syserr2nlerr() below. */
+ return nlerr >= 0
+ ? nlerr
+ : ((nlerr == G_MININT) ? NLE_BUG : -nlerr);
}
static inline int
-nl_syserr2nlerr (int err)
+nl_syserr2nlerr (int errsv)
{
- if (err == G_MININT)
+ /* this maps a native errno to a (always non-negative) netlink error number.
+ *
+ * Note that netlink error numbers are embedded into the range of regular
+ * errno. The only difference is, that netlink error numbers reserve a
+ * range (_NLE_BASE, _NLE_BASE_END) for their own purpose.
+ *
+ * That means, converting an errno to netlink error number means in
+ * most cases just returning itself (negative values are normalized
+ * to be positive). Only values G_MININT and [_NLE_BASE, _NLE_BASE_END]
+ * are coerced to the special value NLE_NATIVE_ERRNO, as they cannot
+ * otherwise be represented in netlink error number domain. */
+ if (errsv == G_MININT)
return NLE_NATIVE_ERRNO;
- if (err < 0)
- err = -err;
- return (err >= _NLE_BASE && err < _NLE_BASE_END)
+ if (errsv < 0)
+ errsv = -errsv;
+ return (errsv >= _NLE_BASE && errsv < _NLE_BASE_END)
? NLE_NATIVE_ERRNO
- : err;
+ : errsv;
}
-const char *nl_geterror (int err);
+const char *nl_geterror (int nlerr);
/*****************************************************************************/