this is the only use of select inside libc i could find. it appears
pretty straightforward to replace with poll.
this compiles, but i have no idea how to test it.
any suggestions? or oks?
Index: net/rcmd.c
===================================================================
RCS file: /cvs/src/lib/libc/net/rcmd.c,v
retrieving revision 1.56
diff -u -p -r1.56 rcmd.c
--- net/rcmd.c 18 Nov 2009 07:43:22 -0000 1.56
+++ net/rcmd.c 9 Oct 2014 04:49:30 -0000
@@ -46,6 +46,7 @@
#include <string.h>
#include <syslog.h>
#include <stdlib.h>
+#include <poll.h>
int
rcmd(char **ahost, int rport, const char *locuser, const char *remuser,
@@ -63,7 +64,6 @@ rcmd_af(char **ahost, int porta, const c
struct addrinfo hints, *res, *r;
int error;
struct sockaddr_storage from;
- fd_set *readsp = NULL;
sigset_t oldmask, mask;
pid_t pid;
int s, lport, timo;
@@ -188,18 +188,14 @@ rcmd_af(char **ahost, int porta, const c
write(s, "", 1);
lport = 0;
} else {
+ struct pollfd pfd[2];
char num[8];
int s2 = rresvport_af(&lport, af), s3;
socklen_t len = sizeof(from);
- int fdssize = howmany(MAX(s, s2)+1, NFDBITS) * sizeof(fd_mask);
if (s2 < 0)
goto bad;
- readsp = (fd_set *)malloc(fdssize);
- if (readsp == NULL) {
- close(s2);
- goto bad;
- }
+
listen(s2, 1);
(void)snprintf(num, sizeof(num), "%d", lport);
if (write(s, num, strlen(num)+1) != strlen(num)+1) {
@@ -210,12 +206,15 @@ rcmd_af(char **ahost, int porta, const c
goto bad;
}
again:
- bzero(readsp, fdssize);
- FD_SET(s, readsp);
- FD_SET(s2, readsp);
+ memset(pfd, 0, sizeof(pfd));
+ pfd[0].fd = s;
+ pfd[0].events = POLLIN;
+ pfd[1].fd = s2;
+ pfd[1].events = POLLIN;
+
errno = 0;
- if (select(MAX(s, s2) + 1, readsp, 0, 0, 0) < 1 ||
- !FD_ISSET(s2, readsp)) {
+ if (poll(pfd, 2, INFTIM) < 1 ||
+ (pfd[1].revents & POLLIN) == 0) {
if (errno != 0)
(void)fprintf(stderr,
"rcmd: select (setting up stderr): %s\n",
@@ -288,14 +287,11 @@ again:
goto bad2;
}
sigprocmask(SIG_SETMASK, &oldmask, NULL);
- free(readsp);
return (s);
bad2:
if (lport)
(void)close(*fd2p);
bad:
- if (readsp)
- free(readsp);
(void)close(s);
sigprocmask(SIG_SETMASK, &oldmask, NULL);
return (-1);