diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2003-08-20 00:28:01 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2003-08-20 00:28:01 +0000 |
commit | e57acc3c8d66f0fa105433d68945ac359d17f57f (patch) | |
tree | e699db0162c95540d68f89c01857ac58f4831726 | |
parent | e7db268bb31fed767ab31e00816ace537ea48ff6 (diff) |
Convert from select to poll; based on a patch from deraadt@
OK deraadt@
-rw-r--r-- | usr.sbin/bootpd/bootpd.c | 39 | ||||
-rw-r--r-- | usr.sbin/bootpd/bootpgw.c | 43 | ||||
-rw-r--r-- | usr.sbin/bootpd/bootptest.c | 16 |
3 files changed, 46 insertions, 52 deletions
diff --git a/usr.sbin/bootpd/bootpd.c b/usr.sbin/bootpd/bootpd.c index 7587924539c..e18e8cbf891 100644 --- a/usr.sbin/bootpd/bootpd.c +++ b/usr.sbin/bootpd/bootpd.c @@ -21,7 +21,7 @@ SOFTWARE. ************************************************************************/ #ifndef lint -static char rcsid[] = "$Id: bootpd.c,v 1.13 2003/07/08 20:41:13 deraadt Exp $"; +static char rcsid[] = "$Id: bootpd.c,v 1.14 2003/08/20 00:27:59 millert Exp $"; #endif /* @@ -60,6 +60,7 @@ static char rcsid[] = "$Id: bootpd.c,v 1.13 2003/07/08 20:41:13 deraadt Exp $"; #include <stdlib.h> #include <signal.h> #include <stdio.h> +#include <poll.h> #include <string.h> #include <errno.h> #include <ctype.h> @@ -147,11 +148,6 @@ struct sockaddr_in send_addr; /* destination */ * option defaults */ int debug = 0; /* Debugging flag (level) */ -struct timeval actualtimeout = -{ /* fifteen minutes */ - 15 * 60L, /* tv_sec */ - 0 /* tv_usec */ -}; /* * General @@ -186,14 +182,14 @@ char *bootpd_dump = DUMPTAB_FILE; int main(int argc, char *argv[]) { - struct timeval *timeout; struct bootp *bp; struct servent *servp; struct hostent *hep; + struct pollfd pfd[1]; char *stmp; int n; socklen_t ba_len, ra_len; - int nfound, readfds; + int nfound, timeout; int standalone; progname = strrchr(argv[0], '/'); @@ -250,7 +246,7 @@ main(int argc, char *argv[]) * Set defaults that might be changed by option switches. */ stmp = NULL; - timeout = &actualtimeout; + timeout = 15 * 60 * 1000; /* fifteen minutes */ /* * Read switches. @@ -336,13 +332,15 @@ main(int argc, char *argv[]) "%s: invalid timeout specification\n", progname); break; } - actualtimeout.tv_sec = (int32) (60 * n); /* - * If the actual timeout is zero, pass a NULL pointer - * to select so it blocks indefinitely, otherwise, - * point to the actual timeout value. + * If the actual timeout is zero, pass INFTIM + * to poll so it blocks indefinitely, otherwise, + * set to the actual timeout value. */ - timeout = (n > 0) ? &actualtimeout : NULL; + if (n > 0) + timeout = n * 60 * 1000; + else + timeout = INFTIM; break; default: @@ -404,7 +402,7 @@ main(int argc, char *argv[]) /* * Nuke any timeout value */ - timeout = NULL; + timeout = INFTIM; } /* if standalone (1st) */ @@ -490,12 +488,13 @@ main(int argc, char *argv[]) /* * Process incoming requests. */ + pfd[0].fd = s; + pfd[0].events = POLLIN; for (;;) { - readfds = 1 << s; - nfound = select(s + 1, (fd_set *)&readfds, NULL, NULL, timeout); + nfound = poll(pfd, 1, timeout); if (nfound < 0) { if (errno != EINTR) { - report(LOG_ERR, "select: %s", get_errmsg()); + report(LOG_ERR, "poll: %s", get_errmsg()); } /* * Call readtab() or dumptab() here to avoid the @@ -511,10 +510,10 @@ main(int argc, char *argv[]) } continue; } - if (!(readfds & (1 << s))) { + if (!(pfd[0].revents & POLLIN)) { if (debug > 1) report(LOG_INFO, "exiting after %ld minutes of inactivity", - actualtimeout.tv_sec / 60); + timeout / (60 * 1000)); exit(0); } ra_len = sizeof(recv_addr); diff --git a/usr.sbin/bootpd/bootpgw.c b/usr.sbin/bootpd/bootpgw.c index a15a428c33b..8bfbb240f73 100644 --- a/usr.sbin/bootpd/bootpgw.c +++ b/usr.sbin/bootpd/bootpgw.c @@ -26,7 +26,7 @@ SOFTWARE. ************************************************************************/ #ifndef lint -static char rcsid[] = "$Id: bootpgw.c,v 1.4 2002/09/06 19:52:26 deraadt Exp $"; +static char rcsid[] = "$Id: bootpgw.c,v 1.5 2003/08/20 00:27:59 millert Exp $"; #endif /* @@ -51,6 +51,7 @@ static char rcsid[] = "$Id: bootpgw.c,v 1.4 2002/09/06 19:52:26 deraadt Exp $"; #endif #include <stdlib.h> #include <signal.h> +#include <poll.h> #include <stdio.h> #include <string.h> #include <errno.h> @@ -121,11 +122,6 @@ struct sockaddr_in serv_addr; /* server address */ * option defaults */ int debug = 0; /* Debugging flag (level) */ -struct timeval actualtimeout = -{ /* fifteen minutes */ - 15 * 60L, /* tv_sec */ - 0 /* tv_usec */ -}; u_int maxhops = 4; /* Number of hops allowed for requests. */ u_int minwait = 3; /* Number of seconds client must wait before its bootrequest packets are forwarded. */ @@ -152,18 +148,16 @@ struct in_addr my_ip_addr; */ int -main(argc, argv) - int argc; - char **argv; +main(int argc, char *argv[]) { - struct timeval *timeout; struct bootp *bp; struct servent *servp; struct hostent *hep; char *stmp; int n; socklen_t ba_len, ra_len; - int nfound, readfds; + int nfound, timeout; + struct pollfd pfd[1]; int standalone; progname = strrchr(argv[0], '/'); @@ -219,7 +213,7 @@ main(argc, argv) * Set defaults that might be changed by option switches. */ stmp = NULL; - timeout = &actualtimeout; + timeout = 15 * 60 * 1000; /* fifteen minutes */ gethostname(myhostname, sizeof(myhostname)); hep = gethostbyname(myhostname); if (!hep) { @@ -298,13 +292,15 @@ main(argc, argv) "%s: invalid timeout specification\n", progname); break; } - actualtimeout.tv_sec = (int32) (60 * n); /* - * If the actual timeout is zero, pass a NULL pointer - * to select so it blocks indefinitely, otherwise, - * point to the actual timeout value. + * If the actual timeout is zero, pass INFTIM + * to poll so it blocks indefinitely, otherwise, + * set to the actual timeout value. */ - timeout = (n > 0) ? &actualtimeout : NULL; + if (n > 0) + timeout = n * 60 * 1000; + else + timeout = INFTIM; break; case 'w': /* wait time */ @@ -378,7 +374,7 @@ main(argc, argv) /* * Nuke any timeout value */ - timeout = NULL; + timeout = INFTIM; /* * Here, bootpd would do: @@ -439,18 +435,19 @@ main(argc, argv) /* * Process incoming requests. */ + pfd[0].fd = s; + pfd[0].events = POLLIN; for (;;) { - readfds = 1 << s; - nfound = select(s + 1, (fd_set *)&readfds, NULL, NULL, timeout); + nfound = poll(pfd, 1, timeout); if (nfound < 0) { if (errno != EINTR) { - report(LOG_ERR, "select: %s", get_errmsg()); + report(LOG_ERR, "poll: %s", get_errmsg()); } continue; } - if (!(readfds & (1 << s))) { + if (!(pfd[0].revents & POLLIN)) { report(LOG_INFO, "exiting after %ld minutes of inactivity", - actualtimeout.tv_sec / 60); + timeout / (60 * 1000)); exit(0); } ra_len = sizeof(clnt_addr); diff --git a/usr.sbin/bootpd/bootptest.c b/usr.sbin/bootpd/bootptest.c index 05c649deb9a..88d4cb8863e 100644 --- a/usr.sbin/bootpd/bootptest.c +++ b/usr.sbin/bootpd/bootptest.c @@ -51,6 +51,7 @@ char *usage = "bootptest [-h] server-name [vendor-data-template-file]"; #include <string.h> #include <errno.h> #include <ctype.h> +#include <poll.h> #include <netdb.h> #include <assert.h> #include <unistd.h> @@ -108,7 +109,7 @@ unsigned char vm_cmu[4] = VM_CMU; unsigned char vm_rfc1048[4] = VM_RFC1048; short secs; /* How long client has waited */ -char *get_errmsg(); +char *get_errmsg(void); extern void bootp_print(); /* @@ -131,6 +132,7 @@ main(argc, argv) int s; /* Socket file descriptor */ int n, tolen, recvcnt; socklen_t fromlen; + struct pollfd pfd[1]; int use_hwa = 0; int32 vend_magic; int32 xid; @@ -366,16 +368,12 @@ main(argc, argv) recvcnt = 0; bp->bp_secs = secs = 0; send_request(s); + pfd[0].fd = s; + pfd[0].events = POLLIN; while (1) { - struct timeval tv; - int readfds; - - tv.tv_sec = WAITSECS; - tv.tv_usec = 0L; - readfds = (1 << s); - n = select(s + 1, (fd_set *) & readfds, NULL, NULL, &tv); + n = poll(pfd, 1, WAITSECS * 1000); if (n < 0) { - perror("select"); + perror("poll"); break; } if (n == 0) { |