Hi there, Similar to the nfsd patch recently, replacing select() with poll() and removing some unecessary variables.
ok? Index: pfkey.c =================================================================== RCS file: /cvs/src/sbin/iked/pfkey.c,v retrieving revision 1.34 diff -u -p -u -r1.34 pfkey.c --- pfkey.c 6 May 2014 10:24:22 -0000 1.34 +++ pfkey.c 7 May 2014 00:20:06 -0000 @@ -35,6 +35,7 @@ #include <stdlib.h> #include <unistd.h> #include <event.h> +#include <poll.h> #include "iked.h" #include "ikev2.h" @@ -43,7 +44,6 @@ #define IOV_CNT 20 #define PFKEYV2_CHUNK sizeof(u_int64_t) -#define PFKEY_REPLY_TIMEOUT 1000 static u_int32_t sadb_msg_seq = 0; static u_int sadb_decoupled = 0; @@ -1086,11 +1086,10 @@ pfkey_reply(int sd, u_int8_t **datap, ss { struct pfkey_message *pm; struct sadb_msg hdr; - struct timeval tv; + struct pollfd pfd; ssize_t len; u_int8_t *data; - fd_set *fds; - int n; + int ret, timeout; for (;;) { /* @@ -1100,24 +1099,17 @@ pfkey_reply(int sd, u_int8_t **datap, ss * and if it is not readable in that time, we fail * the read. */ - n = howmany(sd + 1, NFDBITS); - if ((fds = calloc(n, sizeof(fd_mask))) == NULL) { - log_warn("%s: calloc(%lu, %lu) failed", __func__, - (unsigned long) n, - (unsigned long) sizeof(fd_mask)); - return (-1); - } - FD_SET(sd, fds); - tv.tv_sec = 0; - tv.tv_usec = PFKEY_REPLY_TIMEOUT; - n = select(sd + 1, fds, 0, 0, &tv); - free(fds); - if (n == -1) { - log_warn("%s: select(%d, fds, 0, 0, &tv) failed", - __func__, sd + 1); + + timeout = 1; + pfd.fd = sd; + pfd.events = POLLIN; + ret = poll(&pfd, 1, timeout); + + if (ret == -1) { + log_warn("%s: poll", __func__); return (-1); } - if (n == 0) { + if (ret == 0) { log_warnx("%s: no reply from PF_KEY", __func__); return (-1); } -- Peter Malone <pe...@petermalone.org>