diff --git a/libndp/libndp.c b/libndp/libndp.c index 283de77..3fe89ee 100644 --- a/libndp/libndp.c +++ b/libndp/libndp.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include @@ -2108,22 +2108,20 @@ int ndp_call_eventfd_handler(struct ndp *ndp) NDP_EXPORT int ndp_callall_eventfd_handler(struct ndp *ndp) { - fd_set rfds; - int fdmax; - struct timeval tv; - int fd = ndp_get_eventfd(ndp); + struct pollfd pfd; int ret; int err; - memset(&tv, 0, sizeof(tv)); - FD_ZERO(&rfds); - FD_SET(fd, &rfds); - fdmax = fd + 1; + pfd = (struct pollfd) { + .fd = ndp_get_eventfd(ndp), + .events = POLLIN, + }; + while (true) { - ret = select(fdmax, &rfds, NULL, NULL, &tv); + ret = poll(&pfd, 1, 0); if (ret == -1) return -errno; - if (!FD_ISSET(fd, &rfds)) + if (!(pfd.revents & POLLIN)) return 0; err = ndp_call_eventfd_handler(ndp); if (err) diff --git a/utils/Makefile.am b/utils/Makefile.am index cca00c2..75e452c 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -2,7 +2,7 @@ MAINTAINERCLEANFILES = Makefile.in ACLOCAL_AMFLAGS = -I m4 -AM_CFLAGS = -I${top_srcdir}/include +AM_CFLAGS = -I${top_srcdir}/include -D_GNU_SOURCE ndptool_LDADD = $(top_builddir)/libndp/libndp.la diff --git a/utils/Makefile.in b/utils/Makefile.in index 1507b64..e59263c 100644 --- a/utils/Makefile.in +++ b/utils/Makefile.in @@ -293,7 +293,7 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ MAINTAINERCLEANFILES = Makefile.in ACLOCAL_AMFLAGS = -I m4 -AM_CFLAGS = -I${top_srcdir}/include +AM_CFLAGS = -I${top_srcdir}/include -D_GNU_SOURCE ndptool_LDADD = $(top_builddir)/libndp/libndp.la ndptool_SOURCES = ndptool.c all: all-am diff --git a/utils/ndptool.c b/utils/ndptool.c index 4eca83d..d4d9baf 100644 --- a/utils/ndptool.c +++ b/utils/ndptool.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include enum verbosity_level { VERB1, @@ -59,13 +59,10 @@ static void empty_signal_handler(int signal) static int run_main_loop(struct ndp *ndp) { - fd_set rfds; - fd_set rfds_tmp; - int fdmax; + struct pollfd pfd; int ret; struct sigaction siginfo; sigset_t mask; - int ndp_fd; int err = 0; sigemptyset(&siginfo.sa_mask); @@ -100,23 +97,22 @@ static int run_main_loop(struct ndp *ndp) sigemptyset(&mask); - FD_ZERO(&rfds); - ndp_fd = ndp_get_eventfd(ndp); - FD_SET(ndp_fd, &rfds); - fdmax = ndp_fd + 1; + pfd = (struct pollfd) { + .fd = ndp_get_eventfd(ndp), + .events = POLLIN, + }; for (;;) { - rfds_tmp = rfds; - ret = pselect(fdmax, &rfds_tmp, NULL, NULL, NULL, &mask); + ret = ppoll(&pfd, 1, NULL, &mask); if (ret == -1) { if (errno == EINTR) { goto out; } - pr_err("Select failed\n"); + pr_err("Poll failed\n"); err = -errno; goto out; } - if (FD_ISSET(ndp_fd, &rfds_tmp)) { + if (pfd.revents & POLLIN) { err = ndp_call_eventfd_handler(ndp); if (err) { pr_err("ndp eventfd handler call failed\n");