From c079388c13eb689eaac41647e8cd50d75726069f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Wed, 13 Jul 2005 07:58:36 +0000 Subject: [PATCH] (nl_getlist): poll to get messages from kernel, and retry if the message was lost (free_nlmsglist): free all linked elements, not just the first one git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@15640 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/roken/getifaddrs.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/roken/getifaddrs.c b/lib/roken/getifaddrs.c index 8df224f49..4800dd4ea 100644 --- a/lib/roken/getifaddrs.c +++ b/lib/roken/getifaddrs.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 - 2002 Kungliga Tekniska Högskolan + * Copyright (c) 2000 - 2002, 2005 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). * All rights reserved. * @@ -108,6 +108,7 @@ struct mbuf; #include #include #include +#include #include #include /* the L2 protocols */ #include @@ -378,13 +379,30 @@ nl_getlist(int sd, int seq, struct nlmsghdr *nlh = NULL; int status; int done = 0; + int tries = 3; + try_again: status = nl_sendreq(sd, request, NLM_F_ROOT|NLM_F_MATCH, &seq); if (status < 0) return status; if (seq == 0) seq = (int)time(NULL); while(!done){ + struct pollfd pfd; + + pfd.fd = sd; + pfd.events = POLLIN | POLLPRI; + pfd.revents = 0; + status = poll(&pfd, 1, 1000); + if (status < 0) + return status; + else if (status == 0) { + seq++; + if (tries-- > 0) + goto try_again; + return -1; + } + status = nl_getmsg(sd, request, seq, &nlh, &done); if (status < 0) return status; @@ -417,16 +435,17 @@ nl_getlist(int sd, int seq, static void free_nlmsglist(struct nlmsg_list *nlm0) { - struct nlmsg_list *nlm; + struct nlmsg_list *nlm, *nlm_next; int saved_errno; if (!nlm0) return; saved_errno = errno; - for (nlm=nlm0; nlm; nlm=nlm->nlm_next){ + for (nlm=nlm0; nlm; nlm=nlm_next){ if (nlm->nlh) free(nlm->nlh); + nlm_next=nlm->nlm_next; + free(nlm); } - free(nlm0); __set_errno(saved_errno); }