From 6f156a7b58318669cf883f1b43e0f82a961eb9d5 Mon Sep 17 00:00:00 2001 From: Thomas Graf Date: Tue, 8 May 2012 22:48:00 +0200 Subject: [PATCH] nl: Fix return value of nl_recvmsgs() Apparently the change to have nl_recvmsgs() return the number of parsed messages broke nl_wait_for_ack() among other applications. This patch reverts to the old behaviour and provides a new function nl_recvmsgs_report() which provides the additional information for use by the cache manager and possibly other applications. Reported-by: Scott Bonar Signed-off-by: Thomas Graf --- include/netlink/netlink.h | 1 + lib/cache_mngr.c | 2 +- lib/nl.c | 34 +++++++++++++++++++++++++++++----- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/include/netlink/netlink.h b/include/netlink/netlink.h index 0768708..a501eaa 100644 --- a/include/netlink/netlink.h +++ b/include/netlink/netlink.h @@ -71,6 +71,7 @@ extern int nl_recv(struct nl_sock *, struct ucred **); extern int nl_recvmsgs(struct nl_sock *, struct nl_cb *); +extern int nl_recvmsgs_report(struct nl_sock *, struct nl_cb *); extern int nl_recvmsgs_default(struct nl_sock *); diff --git a/lib/cache_mngr.c b/lib/cache_mngr.c index dae8768..0f0df51 100644 --- a/lib/cache_mngr.c +++ b/lib/cache_mngr.c @@ -359,7 +359,7 @@ int nl_cache_mngr_data_ready(struct nl_cache_mngr *mngr) nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, event_input, mngr); - while ((err = nl_recvmsgs(mngr->cm_sock, cb)) > 0) { + while ((err = nl_recvmsgs_report(mngr->cm_sock, cb)) > 0) { NL_DBG(2, "Cache manager %p, recvmsgs read %d messages\n", mngr, err); nread += err; diff --git a/lib/nl.c b/lib/nl.c index c41a3b9..7e59130 100644 --- a/lib/nl.c +++ b/lib/nl.c @@ -762,6 +762,26 @@ out: return err; } +/** + * Receive a set of messages from a netlink socket and report parsed messages + * @arg sk Netlink socket. + * @arg cb set of callbacks to control behaviour. + * + * This function is identical to nl_recvmsgs() to the point that it will + * return the number of parsed messages instead of 0 on success. + * + * @see nl_recvmsgs() + * + * @return Number of received messages or a negative error code from nl_recv(). + */ +int nl_recvmsgs_report(struct nl_sock *sk, struct nl_cb *cb) +{ + if (cb->cb_recvmsgs_ow) + return cb->cb_recvmsgs_ow(sk, cb); + else + return recvmsgs(sk, cb); +} + /** * Receive a set of messages from a netlink socket. * @arg sk Netlink socket. @@ -775,14 +795,18 @@ out: * A non-blocking sockets causes the function to return immediately if * no data is available. * - * @return Number of received messages or a negative error code from nl_recv(). + * @see nl_recvmsgs_report() + * + * @return 0 on success or a negative error code from nl_recv(). */ int nl_recvmsgs(struct nl_sock *sk, struct nl_cb *cb) { - if (cb->cb_recvmsgs_ow) - return cb->cb_recvmsgs_ow(sk, cb); - else - return recvmsgs(sk, cb); + int err; + + if ((err = nl_recvmsgs_report(sk, cb)) > 0) + err = 0; + + return err; } /**