rc == -1 and errno == EINTR mean: mnl_socket_recvfrom() - blindly rerun the function mnl_cb_run() - restart dump request from scratch This commit introduces handling of both these conditions Signed-off-by: Eugene Crosser <crosser@xxxxxxxxxxx> --- src/iface.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/iface.c b/src/iface.c index d0e1834c..5ecc087d 100644 --- a/src/iface.c +++ b/src/iface.c @@ -59,14 +59,14 @@ static int data_cb(const struct nlmsghdr *nlh, void *data) return MNL_CB_OK; } -void iface_cache_update(void) +static int __iface_cache_update(void) { char buf[MNL_SOCKET_BUFFER_SIZE]; struct mnl_socket *nl; struct nlmsghdr *nlh; struct rtgenmsg *rt; uint32_t seq, portid; - int ret; + int ret = -1; nlh = mnl_nlmsg_put_header(buf); nlh->nlmsg_type = RTM_GETLINK; @@ -77,28 +77,39 @@ void iface_cache_update(void) nl = mnl_socket_open(NETLINK_ROUTE); if (nl == NULL) - netlink_init_error(); + return -1; if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) - netlink_init_error(); + goto close_and_return; portid = mnl_socket_get_portid(nl); if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) - netlink_init_error(); + goto close_and_return; - ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); - while (ret > 0) { - ret = mnl_cb_run(buf, ret, seq, portid, data_cb, NULL); - if (ret <= MNL_CB_STOP) + do { + do ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); + while (ret == -1 && errno == EINTR); + if (ret == -1) break; - ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); - } - if (ret == -1) - netlink_init_error(); + ret = mnl_cb_run(buf, ret, seq, portid, data_cb, NULL); + } while (ret > MNL_CB_STOP); +close_and_return: mnl_socket_close(nl); + return ret; +} + +void iface_cache_update(void) +{ + int ret; + + do ret = __iface_cache_update(); + while (ret == -1 && errno == EINTR); + if (ret == -1) + netlink_init_error(); + iface_cache_init = true; } -- 2.32.0