From e4ff1e9261395c53e37117ff04c8c33501931e66 Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kain" Date: Sun, 3 Jul 2011 18:10:00 -0400 Subject: [PATCH] Remove the ugly hack for forcing nl_getifdata() to be synchronous. It now properly performs a synchronous wait using poll(). --- ndhc/netlink.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ndhc/netlink.c b/ndhc/netlink.c index 7d2814d..39dd913 100644 --- a/ndhc/netlink.c +++ b/ndhc/netlink.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "netlink.h" #include "ifchange.h" @@ -192,12 +193,13 @@ int nl_getifdata(const char *ifname, struct client_state_t *cs) sizeof addr) == -1) return -1; - // This is rather ugly, but hey! - if (fcntl(cs->nlFd, F_SETFL, fcntl(cs->nlFd, F_GETFL) & ~O_NONBLOCK) == -1) - suicide("nl_getifdata: failed to remove O_NONBLOCK"); - handle_nl_message(cs); - if (fcntl(cs->nlFd, F_SETFL, fcntl(cs->nlFd, F_GETFL) | O_NONBLOCK) == -1) - suicide("nl_getifdata: failed to restore O_NONBLOCK"); + for (int pr = 0; !pr;) { + pr = poll(&((struct pollfd){.fd=cs->nlFd,.events=POLLIN}), 1, -1); + if (pr == 1) + handle_nl_message(cs); + else if (pr == -1) + suicide("nl: poll failed"); + } return 0; }