summaryrefslogtreecommitdiffstats
path: root/lib/attr.c
diff options
context:
space:
mode:
authorThomas Graf <tgr@lsx.localdomain>2008-05-14 15:49:44 (GMT)
committerThomas Graf <tgr@lsx.localdomain>2008-05-14 15:49:44 (GMT)
commit8a3efffa5b3fde252675239914118664d36a2c24 (patch)
treef8efc71b2bd4736f2a56084efea05d7ee191a422 /lib/attr.c
parent85f932552e61c5997c1e83fe386098c94d93c273 (diff)
downloadlibnl-8a3efffa5b3fde252675239914118664d36a2c24.zip
libnl-8a3efffa5b3fde252675239914118664d36a2c24.tar.gz
libnl-8a3efffa5b3fde252675239914118664d36a2c24.tar.bz2
Thread-safe error handling
In order for the interface to become more thread safe, the error handling was revised to no longer depend on a static errno and error string buffer. This patch converts all error paths to return a libnl specific error code which can be translated to a error message using nl_geterror(int error). The functions nl_error() and nl_get_errno() are therefore obsolete. This change required various sets of function prototypes to be changed in order to return an error code, the most prominent are: struct nl_cache *foo_alloc_cache(...); changed to: int foo_alloc_cache(..., struct nl_cache **); struct nl_msg *foo_build_request(...); changed to: int foo_build_request(..., struct nl_msg **); struct foo *foo_parse(...); changed to: int foo_parse(..., struct foo **); This pretty much only leaves trivial allocation functions to still return a pointer object which can still return NULL to signal out of memory. This change is a serious API and ABI breaker, sorry!
Diffstat (limited to 'lib/attr.c')
-rw-r--r--lib/attr.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/lib/attr.c b/lib/attr.c
index 875c881..0143be7 100644
--- a/lib/attr.c
+++ b/lib/attr.c
@@ -267,7 +267,7 @@
* return 0;
*
* nla_put_failure:
- * return -ENOMEM;
+ * return -NLE_NOMEM;
* }
* @endcode
*
@@ -544,18 +544,18 @@ static int validate_nla(struct nlattr *nla, int maxtype,
minlen = nla_attr_minlen[pt->type];
if (pt->type == NLA_FLAG && nla_len(nla) > 0)
- return nl_errno(ERANGE);
+ return -NLE_RANGE;
if (nla_len(nla) < minlen)
- return nl_errno(ERANGE);
+ return -NLE_RANGE;
if (pt->maxlen && nla_len(nla) > pt->maxlen)
- return nl_errno(ERANGE);
+ return -NLE_RANGE;
if (pt->type == NLA_STRING) {
char *data = nla_data(nla);
if (data[nla_len(nla) - 1] != '\0')
- return nl_errno(EINVAL);
+ return -NLE_INVAL;
}
return 0;
@@ -802,10 +802,8 @@ struct nlattr *nla_reserve(struct nl_msg *msg, int attrtype, int attrlen)
tlen = NLMSG_ALIGN(msg->nm_nlh->nlmsg_len) + nla_total_size(attrlen);
- if ((tlen + msg->nm_nlh->nlmsg_len) > msg->nm_size) {
- nl_errno(ENOBUFS);
+ if ((tlen + msg->nm_nlh->nlmsg_len) > msg->nm_size)
return NULL;
- }
nla = (struct nlattr *) nlmsg_tail(msg->nm_nlh);
nla->nla_type = attrtype;
@@ -842,7 +840,7 @@ int nla_put(struct nl_msg *msg, int attrtype, int datalen, const void *data)
nla = nla_reserve(msg, attrtype, datalen);
if (!nla)
- return nl_errno(ENOMEM);
+ return -NLE_NOMEM;
memcpy(nla_data(nla), data, datalen);
NL_DBG(2, "msg %p: Wrote %d bytes at offset +%td for attr %d\n",