summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2014-10-29 06:26:41 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2014-10-29 06:26:41 +0000
commit7dcf75f73906f68fa97b39fbaa1cde496a4d70e3 (patch)
treee1da7dc61418e5616ae0337fabc9631f1be21b9c /sbin
parente83494817af5803aa67ba728aa8c331646a03aaa (diff)
convert simple cases of select() to poll()
ok doug
Diffstat (limited to 'sbin')
-rw-r--r--sbin/iked/pfkey.c25
-rw-r--r--sbin/isakmpd/pf_key_v2.c30
2 files changed, 17 insertions, 38 deletions
diff --git a/sbin/iked/pfkey.c b/sbin/iked/pfkey.c
index 5bf0c0985f5..2b826957436 100644
--- a/sbin/iked/pfkey.c
+++ b/sbin/iked/pfkey.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfkey.c,v 1.39 2014/10/18 03:11:54 doug Exp $ */
+/* $OpenBSD: pfkey.c,v 1.40 2014/10/29 06:26:39 deraadt Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -31,6 +31,7 @@
#include <err.h>
#include <errno.h>
#include <stdio.h>
+#include <poll.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
@@ -1097,12 +1098,14 @@ pfkey_reply(int sd, u_int8_t **datap, ssize_t *lenp)
{
struct pfkey_message *pm;
struct sadb_msg hdr;
- struct timeval tv;
ssize_t len;
u_int8_t *data;
- fd_set *fds;
+ struct pollfd pfd[1];
int n;
+ pfd[0].fd = sd;
+ pfd[0].events = POLLIN;
+
for (;;) {
/*
* We should actually expect the reply to get lost
@@ -1111,21 +1114,9 @@ pfkey_reply(int sd, u_int8_t **datap, ssize_t *lenp)
* 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);
+ n = poll(pfd, 1, PFKEY_REPLY_TIMEOUT / 1000);
if (n == -1) {
- log_warn("%s: select(%d, fds, 0, 0, &tv) failed",
- __func__, sd + 1);
+ log_warn("%s: poll() failed", __func__);
return (-1);
}
if (n == 0) {
diff --git a/sbin/isakmpd/pf_key_v2.c b/sbin/isakmpd/pf_key_v2.c
index 782a4d02821..bb2a7ac4fe8 100644
--- a/sbin/isakmpd/pf_key_v2.c
+++ b/sbin/isakmpd/pf_key_v2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf_key_v2.c,v 1.190 2014/10/22 16:35:34 millert Exp $ */
+/* $OpenBSD: pf_key_v2.c,v 1.191 2014/10/29 06:26:40 deraadt Exp $ */
/* $EOM: pf_key_v2.c,v 1.79 2000/12/12 00:33:19 niklas Exp $ */
/*
@@ -43,6 +43,7 @@
#include <netinet/ip_ipsp.h>
#include <arpa/inet.h>
#include <stdlib.h>
+#include <poll.h>
#include <string.h>
#include <unistd.h>
#include <pwd.h>
@@ -203,8 +204,11 @@ pf_key_v2_read(u_int32_t seq)
struct sadb_msg *msg;
struct sadb_msg hdr;
struct sadb_ext *ext;
- struct timeval tv;
- fd_set *fds;
+ struct timeval tv;
+ struct pollfd pfd[1];
+
+ pfd[0].fd = pf_key_v2_socket;
+ pfd[0].events = POLLIN;
while (1) {
/*
@@ -214,25 +218,9 @@ pf_key_v2_read(u_int32_t seq)
* and if it is not readable in that time, we fail the read.
*/
if (seq) {
- fds = calloc(howmany(pf_key_v2_socket + 1, NFDBITS),
- sizeof(fd_mask));
- if (!fds) {
- log_error("pf_key_v2_read: "
- "calloc (%lu, %lu) failed",
- (unsigned long) howmany(pf_key_v2_socket + 1,
- NFDBITS),
- (unsigned long) sizeof(fd_mask));
- goto cleanup;
- }
- FD_SET(pf_key_v2_socket, fds);
- tv.tv_sec = 0;
- tv.tv_usec = PF_KEY_REPLY_TIMEOUT;
- n = select(pf_key_v2_socket + 1, fds, 0, 0, &tv);
- free(fds);
+ n = poll(pfd, 1, PF_KEY_REPLY_TIMEOUT / 1000);
if (n == -1) {
- log_error("pf_key_v2_read: "
- "select (%d, fds, 0, 0, &tv) failed",
- pf_key_v2_socket + 1);
+ log_error("pf_key_v2_read: poll() failed");
goto cleanup;
}
if (!n) {