Having nl_recvmsgs() return the number of read messages allows
to continue reading until the underlying recvmsg() will return
EAGAIN for the non blocking socket.
The reallocated part of the enlarged association array was left
uninitialized which would have resulted in trying to free random
pointers.
This was a theoretical bug because it wasn't possible to register
more than 32 cache types since no netlink family supports that
many individual cache types.
Nevertheless this patch fixes the bug and also reduces the default
size of the allocation table and expandations a bit to reduce the
memory footprint slightly.
The requirement to have the caller provide the socket does not
make much sense. Automatically allocate the socket if none was
provided.
This may also avoid some future abuse of reusing request sockets
for handling notifications.
Also rename cm_handle to cm_sock for clarity (no API change)
Instead, clone it and modify a temporary copy. Although it is not
recommended to use the same socket for requests and to serve a
cache manager, this change might prevent some unwanted side effects
if done so.
the patch below adds the possibility to
pass user data to callbacks of type
change_func_t when using the nl_cache_mngr_*
family of functions.
If there is any better way to do this,
without duplicating the code in
cache_mngr.c please let me know.
The idea of a common handle is long revised and only misleading,
nl_handle really represents a socket with some additional
action handlers assigned to it.
Alias for nl_handle is kept for backwards compatibility.
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!
Caches allocated by the cache manager must be freed again when the cache
manager itself is freed. However, the netlink socket is allocated
indepdently so it should not be freed.