From: Stephen Hemminger <shemminger@vyatta.com>
To: David Ward <david.ward@ll.mit.edu>
Cc: netdev@vger.kernel.org, David Ward <david.ward@ll.mit.edu>
Subject: Re: [RFC] iproute2: gracefully exit from rtnl_listen()
Date: Tue, 1 Sep 2009 15:59:55 -0700 [thread overview]
Message-ID: <20090901155955.7448c1d6@nehalam> (raw)
In-Reply-To: <1251841286-32463-1-git-send-email-david.ward@ll.mit.edu>
On Tue, 1 Sep 2009 17:41:26 -0400
David Ward <david.ward@ll.mit.edu> wrote:
> rtnl_listen() (in iproute2's libnetlink) allows a userspace application to
> monitor an RTNETLINK multicast group, so that the application can react to
> changes in the kernel's routing table, neighbor cache, etc. as they occur.
> (This is in contrast with using RTNETLINK to solicit the kernel for a full
> copy of the routing table or neighbor cache at a specific point in time.)
>
> However rtnl_listen() creates an infinite loop, which does not break in the
> absence of errors, so there does not seem to be any way to gracefully exit
> from it. Existing applications that call rtnl_listen(), such as rtmon, break
> from this loop by terminating the entire application. There should be some
> mechanism for stopping rtnl_listen() and continuing program execution.
>
> If you assume that rtnl_listen() will only need to be stopped because the
> application has received a signal (such as SIGINT), then the application's
> signal handler can call rtnl_close() to close the RTNETLINK socket.
> Afterwards, with this patch, rtnl_listen() can detect that the socket was
> closed during the interrupt and exit.
>
> I am offering this as a starting point for consideration, but I feel that
> this is at best a poor solution. What is a better way to fix rtnl_listen()
> (and similar libnetlink functions for consistency)?
> ---
> lib/libnetlink.c | 15 ++++++++++++---
> 1 files changed, 12 insertions(+), 3 deletions(-)
Good idea, but why not just change the while(1) loop?
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index b68e2fd..cecfa34 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -188,7 +188,7 @@ int rtnl_dump_filter(struct rtnl_handle *rth,
char buf[16384];
iov.iov_base = buf;
- while (1) {
+ while (rtnl->fd >= 0) {
int status;
struct nlmsghdr *h;
@@ -200,12 +200,12 @@ int rtnl_dump_filter(struct rtnl_handle *rth,
continue;
fprintf(stderr, "netlink receive error %s (%d)\n",
strerror(errno), errno);
- return -1;
+ break;
}
if (status == 0) {
fprintf(stderr, "EOF on netlink\n");
- return -1;
+ break;
}
h = (struct nlmsghdr*)buf;
@@ -251,6 +251,8 @@ skip_it:
exit(1);
}
}
+
+ return -1;
}
int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
next prev parent reply other threads:[~2009-09-01 22:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-01 21:41 [RFC] iproute2: gracefully exit from rtnl_listen() David Ward
2009-09-01 22:59 ` Stephen Hemminger [this message]
2009-09-02 2:27 ` David Ward
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090901155955.7448c1d6@nehalam \
--to=shemminger@vyatta.com \
--cc=david.ward@ll.mit.edu \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.