diff options
author | Darren Tucker <dtucker@zip.com.au> | 2007-06-25 22:15:12 +1000 |
---|---|---|
committer | Darren Tucker <dtucker@zip.com.au> | 2007-06-25 22:15:12 +1000 |
commit | febf0f5668f997c63210b3dbd50ce5443b0f6aea (patch) | |
tree | df7829b7c652ba79cd3d2a357dbf5a4b083de6da | |
parent | dc4a779fbbefd662e1b0b4dd2417329826ff264f (diff) |
- (dtucker) [atomicio.c configure.ac openbsd-compat/Makefile.in
openbsd-compat/bsd-poll.{c,h} openbsd-compat/openbsd-compat.h]
Add an implementation of poll() built on top of select(2). Code from
OpenNTPD with changes suggested by djm. ok djm@
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | atomicio.c | 2 | ||||
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | openbsd-compat/Makefile.in | 4 | ||||
-rw-r--r-- | openbsd-compat/bsd-poll.c | 117 | ||||
-rw-r--r-- | openbsd-compat/bsd-poll.h | 61 | ||||
-rw-r--r-- | openbsd-compat/openbsd-compat.h | 3 |
7 files changed, 193 insertions, 6 deletions
@@ -25,6 +25,10 @@ | |||
25 | Include <poll.h> like the man page says rather than <sys/poll.h>. ok djm@ | 25 | Include <poll.h> like the man page says rather than <sys/poll.h>. ok djm@ |
26 | - (dtucker) [atomicio.c] Test for EWOULDBLOCK in atomiciov to match | 26 | - (dtucker) [atomicio.c] Test for EWOULDBLOCK in atomiciov to match |
27 | atomicio. | 27 | atomicio. |
28 | - (dtucker) [atomicio.c configure.ac openbsd-compat/Makefile.in | ||
29 | openbsd-compat/bsd-poll.{c,h} openbsd-compat/openbsd-compat.h] | ||
30 | Add an implementation of poll() built on top of select(2). Code from | ||
31 | OpenNTPD with changes suggested by djm. ok djm@ | ||
28 | 32 | ||
29 | 20070614 | 33 | 20070614 |
30 | - (dtucker) [cipher-ctr.c umac.c openbsd-compat/openssl-compat.h] Move the | 34 | - (dtucker) [cipher-ctr.c umac.c openbsd-compat/openssl-compat.h] Move the |
@@ -3100,4 +3104,4 @@ | |||
3100 | OpenServer 6 and add osr5bigcrypt support so when someone migrates | 3104 | OpenServer 6 and add osr5bigcrypt support so when someone migrates |
3101 | passwords between UnixWare and OpenServer they will still work. OK dtucker@ | 3105 | passwords between UnixWare and OpenServer they will still work. OK dtucker@ |
3102 | 3106 | ||
3103 | $Id: ChangeLog,v 1.4709 2007/06/25 12:08:10 dtucker Exp $ | 3107 | $Id: ChangeLog,v 1.4710 2007/06/25 12:15:12 dtucker Exp $ |
diff --git a/atomicio.c b/atomicio.c index afe3444c9..f32ff85ba 100644 --- a/atomicio.c +++ b/atomicio.c | |||
@@ -32,7 +32,9 @@ | |||
32 | #include <sys/uio.h> | 32 | #include <sys/uio.h> |
33 | 33 | ||
34 | #include <errno.h> | 34 | #include <errno.h> |
35 | #ifdef HAVE_POLL_H | ||
35 | #include <poll.h> | 36 | #include <poll.h> |
37 | #endif | ||
36 | #include <string.h> | 38 | #include <string.h> |
37 | #include <unistd.h> | 39 | #include <unistd.h> |
38 | 40 | ||
diff --git a/configure.ac b/configure.ac index 143c164a9..689724133 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -1,4 +1,4 @@ | |||
1 | # $Id: configure.ac,v 1.381 2007/06/11 04:15:43 djm Exp $ | 1 | # $Id: configure.ac,v 1.382 2007/06/25 12:15:12 dtucker Exp $ |
2 | # | 2 | # |
3 | # Copyright (c) 1999-2004 Damien Miller | 3 | # Copyright (c) 1999-2004 Damien Miller |
4 | # | 4 | # |
@@ -15,7 +15,7 @@ | |||
15 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 15 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
16 | 16 | ||
17 | AC_INIT(OpenSSH, Portable, openssh-unix-dev@mindrot.org) | 17 | AC_INIT(OpenSSH, Portable, openssh-unix-dev@mindrot.org) |
18 | AC_REVISION($Revision: 1.381 $) | 18 | AC_REVISION($Revision: 1.382 $) |
19 | AC_CONFIG_SRCDIR([ssh.c]) | 19 | AC_CONFIG_SRCDIR([ssh.c]) |
20 | 20 | ||
21 | AC_CONFIG_HEADER(config.h) | 21 | AC_CONFIG_HEADER(config.h) |
@@ -205,6 +205,7 @@ AC_CHECK_HEADERS( \ | |||
205 | netgroup.h \ | 205 | netgroup.h \ |
206 | pam/pam_appl.h \ | 206 | pam/pam_appl.h \ |
207 | paths.h \ | 207 | paths.h \ |
208 | poll.h \ | ||
208 | pty.h \ | 209 | pty.h \ |
209 | readpassphrase.h \ | 210 | readpassphrase.h \ |
210 | rpc/types.h \ | 211 | rpc/types.h \ |
@@ -1267,6 +1268,7 @@ AC_CHECK_FUNCS( \ | |||
1267 | ogetaddrinfo \ | 1268 | ogetaddrinfo \ |
1268 | openlog_r \ | 1269 | openlog_r \ |
1269 | openpty \ | 1270 | openpty \ |
1271 | poll \ | ||
1270 | prctl \ | 1272 | prctl \ |
1271 | pstat \ | 1273 | pstat \ |
1272 | readpassphrase \ | 1274 | readpassphrase \ |
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in index 9f06605d7..b44a7851e 100644 --- a/openbsd-compat/Makefile.in +++ b/openbsd-compat/Makefile.in | |||
@@ -1,4 +1,4 @@ | |||
1 | # $Id: Makefile.in,v 1.40 2006/08/30 17:24:41 djm Exp $ | 1 | # $Id: Makefile.in,v 1.41 2007/06/25 12:15:13 dtucker Exp $ |
2 | 2 | ||
3 | sysconfdir=@sysconfdir@ | 3 | sysconfdir=@sysconfdir@ |
4 | piddir=@piddir@ | 4 | piddir=@piddir@ |
@@ -18,7 +18,7 @@ LDFLAGS=-L. @LDFLAGS@ | |||
18 | 18 | ||
19 | OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getopt.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sha2.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o strtonum.o strtoll.o strtoul.o vis.o | 19 | OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getopt.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sha2.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o strtonum.o strtoll.o strtoul.o vis.o |
20 | 20 | ||
21 | COMPAT=bsd-arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-snprintf.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xmmap.o xcrypt.o | 21 | COMPAT=bsd-arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-snprintf.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xmmap.o xcrypt.o |
22 | 22 | ||
23 | PORTS=port-aix.o port-irix.o port-linux.o port-solaris.o port-tun.o port-uw.o | 23 | PORTS=port-aix.o port-irix.o port-linux.o port-solaris.o port-tun.o port-uw.o |
24 | 24 | ||
diff --git a/openbsd-compat/bsd-poll.c b/openbsd-compat/bsd-poll.c new file mode 100644 index 000000000..836882eea --- /dev/null +++ b/openbsd-compat/bsd-poll.c | |||
@@ -0,0 +1,117 @@ | |||
1 | /* $Id: bsd-poll.c,v 1.1 2007/06/25 12:15:13 dtucker Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2004, 2005, 2007 Darren Tucker (dtucker at zip com au). | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include "includes.h" | ||
20 | #if !defined(HAVE_POLL) && defined(HAVE_SELECT) | ||
21 | |||
22 | #ifdef HAVE_SYS_SELECT_H | ||
23 | # include <sys/select.h> | ||
24 | #endif | ||
25 | |||
26 | #include <errno.h> | ||
27 | #include "bsd-poll.h" | ||
28 | |||
29 | /* | ||
30 | * A minimal implementation of poll(2), built on top of select(2). | ||
31 | * | ||
32 | * Only supports POLLIN and POLLOUT flags in pfd.events, and POLLIN, POLLOUT | ||
33 | * and POLLERR flags in revents. | ||
34 | * | ||
35 | * Supports pfd.fd = -1 meaning "unused" although it's not standard. | ||
36 | */ | ||
37 | |||
38 | int | ||
39 | poll(struct pollfd *fds, nfds_t nfds, int timeout) | ||
40 | { | ||
41 | nfds_t i; | ||
42 | int saved_errno, ret, fd, maxfd = 0; | ||
43 | fd_set *readfds = NULL, *writefds = NULL, *exceptfds = NULL; | ||
44 | size_t nmemb; | ||
45 | struct timeval tv, *tvp = NULL; | ||
46 | |||
47 | for (i = 0; i < nfds; i++) { | ||
48 | if (fd >= FD_SETSIZE) { | ||
49 | errno = EINVAL; | ||
50 | return -1; | ||
51 | } | ||
52 | maxfd = MAX(maxfd, fds[i].fd); | ||
53 | } | ||
54 | |||
55 | nmemb = howmany(maxfd + 1 , NFDBITS); | ||
56 | if ((readfds = calloc(nmemb, sizeof(fd_mask))) == NULL || | ||
57 | (writefds = calloc(nmemb, sizeof(fd_mask))) == NULL || | ||
58 | (exceptfds = calloc(nmemb, sizeof(fd_mask))) == NULL) { | ||
59 | saved_errno = ENOMEM; | ||
60 | ret = -1; | ||
61 | goto out; | ||
62 | } | ||
63 | |||
64 | /* populate event bit vectors for the events we're interested in */ | ||
65 | for (i = 0; i < nfds; i++) { | ||
66 | fd = fds[i].fd; | ||
67 | if (fd == -1) | ||
68 | continue; | ||
69 | if (fds[i].events & POLLIN) { | ||
70 | FD_SET(fd, readfds); | ||
71 | FD_SET(fd, exceptfds); | ||
72 | } | ||
73 | if (fds[i].events & POLLOUT) { | ||
74 | FD_SET(fd, writefds); | ||
75 | FD_SET(fd, exceptfds); | ||
76 | } | ||
77 | } | ||
78 | |||
79 | /* poll timeout is msec, select is timeval (sec + usec) */ | ||
80 | if (timeout >= 0) { | ||
81 | tv.tv_sec = timeout / 1000; | ||
82 | tv.tv_usec = (timeout % 1000) * 1000; | ||
83 | tvp = &tv; | ||
84 | } | ||
85 | |||
86 | ret = select(maxfd + 1, readfds, writefds, exceptfds, tvp); | ||
87 | saved_errno = errno; | ||
88 | |||
89 | /* scan through select results and set poll() flags */ | ||
90 | for (i = 0; i < nfds; i++) { | ||
91 | fd = fds[i].fd; | ||
92 | fds[i].revents = 0; | ||
93 | if (fd == -1) | ||
94 | continue; | ||
95 | if (FD_ISSET(fd, readfds)) { | ||
96 | fds[i].revents |= POLLIN; | ||
97 | } | ||
98 | if (FD_ISSET(fd, writefds)) { | ||
99 | fds[i].revents |= POLLOUT; | ||
100 | } | ||
101 | if (FD_ISSET(fd, exceptfds)) { | ||
102 | fds[i].revents |= POLLERR; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | out: | ||
107 | if (readfds != NULL) | ||
108 | free(readfds); | ||
109 | if (writefds != NULL) | ||
110 | free(writefds); | ||
111 | if (exceptfds != NULL) | ||
112 | free(exceptfds); | ||
113 | if (ret == -1) | ||
114 | errno = saved_errno; | ||
115 | return ret; | ||
116 | } | ||
117 | #endif | ||
diff --git a/openbsd-compat/bsd-poll.h b/openbsd-compat/bsd-poll.h new file mode 100644 index 000000000..dcbb9ca40 --- /dev/null +++ b/openbsd-compat/bsd-poll.h | |||
@@ -0,0 +1,61 @@ | |||
1 | /* $OpenBSD: poll.h,v 1.11 2003/12/10 23:10:08 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 1996 Theo de Raadt | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | /* OPENBSD ORIGINAL: sys/sys/poll.h */ | ||
29 | |||
30 | #if !defined(HAVE_POLL) && !defined(HAVE_POLL_H) | ||
31 | #ifndef _COMPAT_POLL_H_ | ||
32 | #define _COMPAT_POLL_H_ | ||
33 | |||
34 | typedef struct pollfd { | ||
35 | int fd; | ||
36 | short events; | ||
37 | short revents; | ||
38 | } pollfd_t; | ||
39 | |||
40 | typedef unsigned int nfds_t; | ||
41 | |||
42 | #define POLLIN 0x0001 | ||
43 | #define POLLOUT 0x0004 | ||
44 | #define POLLERR 0x0008 | ||
45 | #if 0 | ||
46 | /* the following are currently not implemented */ | ||
47 | #define POLLPRI 0x0002 | ||
48 | #define POLLHUP 0x0010 | ||
49 | #define POLLNVAL 0x0020 | ||
50 | #define POLLRDNORM 0x0040 | ||
51 | #define POLLNORM POLLRDNORM | ||
52 | #define POLLWRNORM POLLOUT | ||
53 | #define POLLRDBAND 0x0080 | ||
54 | #define POLLWRBAND 0x0100 | ||
55 | #endif | ||
56 | |||
57 | #define INFTIM (-1) /* not standard */ | ||
58 | |||
59 | int poll(struct pollfd *, nfds_t, int); | ||
60 | #endif /* !_COMPAT_POLL_H_ */ | ||
61 | #endif /* !HAVE_POLL_H */ | ||
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h index aac2e6cbc..6406af19d 100644 --- a/openbsd-compat/openbsd-compat.h +++ b/openbsd-compat/openbsd-compat.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: openbsd-compat.h,v 1.42 2006/09/03 12:44:50 dtucker Exp $ */ | 1 | /* $Id: openbsd-compat.h,v 1.43 2007/06/25 12:15:13 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 1999-2003 Damien Miller. All rights reserved. | 4 | * Copyright (c) 1999-2003 Damien Miller. All rights reserved. |
@@ -140,6 +140,7 @@ int writev(int, struct iovec *, int); | |||
140 | /* Home grown routines */ | 140 | /* Home grown routines */ |
141 | #include "bsd-misc.h" | 141 | #include "bsd-misc.h" |
142 | #include "bsd-waitpid.h" | 142 | #include "bsd-waitpid.h" |
143 | #include "bsd-poll.h" | ||
143 | 144 | ||
144 | #ifndef HAVE_GETPEEREID | 145 | #ifndef HAVE_GETPEEREID |
145 | int getpeereid(int , uid_t *, gid_t *); | 146 | int getpeereid(int , uid_t *, gid_t *); |