]> andersk Git - openssh.git/commitdiff
- (dtucker) [atomicio.c configure.ac openbsd-compat/Makefile.in
authordtucker <dtucker>
Mon, 25 Jun 2007 12:15:12 +0000 (12:15 +0000)
committerdtucker <dtucker>
Mon, 25 Jun 2007 12:15:12 +0000 (12:15 +0000)
   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@

ChangeLog
atomicio.c
configure.ac
openbsd-compat/Makefile.in
openbsd-compat/bsd-poll.c [new file with mode: 0644]
openbsd-compat/bsd-poll.h [new file with mode: 0644]
openbsd-compat/openbsd-compat.h

index 3be6700583ed50145c64ee8443881994e17236f7..856b5bf6c2ac93fab90b424f1f2833d4315b11bb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
      Include <poll.h> like the man page says rather than <sys/poll.h>.  ok djm@
  - (dtucker) [atomicio.c] Test for EWOULDBLOCK in atomiciov to match
    atomicio.
+ - (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@
 
 20070614
  - (dtucker) [cipher-ctr.c umac.c openbsd-compat/openssl-compat.h] Move the
index afe3444c945c9a85b264ba602cdaaf2f24219ec9..f32ff85baf67abf561ea5ed02b9b3a902bf0aa1d 100644 (file)
@@ -32,7 +32,9 @@
 #include <sys/uio.h>
 
 #include <errno.h>
+#ifdef HAVE_POLL_H
 #include <poll.h>
+#endif
 #include <string.h>
 #include <unistd.h>
 
index b09666f0aa941a5bca3de01a2e7e76ba335545aa..af7abb07a02f5405b33736ccfeaa07404d22932b 100644 (file)
@@ -205,6 +205,7 @@ AC_CHECK_HEADERS( \
        netgroup.h \
        pam/pam_appl.h \
        paths.h \
+       poll.h \
        pty.h \
        readpassphrase.h \
        rpc/types.h \
@@ -1267,6 +1268,7 @@ AC_CHECK_FUNCS( \
        ogetaddrinfo \
        openlog_r \
        openpty \
+       poll \
        prctl \
        pstat \
        readpassphrase \
index be1926b3e3b7fe58f861612ea3f564fec052f9a1..1e13be7e1bbb3ddb65c52cdab56c9304f3de3e65 100644 (file)
@@ -18,7 +18,7 @@ LDFLAGS=-L. @LDFLAGS@
 
 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
 
-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
+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
 
 PORTS=port-aix.o port-irix.o port-linux.o port-solaris.o port-tun.o port-uw.o
 
diff --git a/openbsd-compat/bsd-poll.c b/openbsd-compat/bsd-poll.c
new file mode 100644 (file)
index 0000000..4dd6fc4
--- /dev/null
@@ -0,0 +1,117 @@
+/* $Id$ */
+
+/*
+ * Copyright (c) 2004, 2005, 2007 Darren Tucker (dtucker at zip com au).
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "includes.h"
+#if !defined(HAVE_POLL) && defined(HAVE_SELECT)
+
+#ifdef HAVE_SYS_SELECT_H
+# include <sys/select.h>
+#endif
+
+#include <errno.h>
+#include "bsd-poll.h"
+
+/*
+ * A minimal implementation of poll(2), built on top of select(2).
+ *
+ * Only supports POLLIN and POLLOUT flags in pfd.events, and POLLIN, POLLOUT
+ * and POLLERR flags in revents.
+ *
+ * Supports pfd.fd = -1 meaning "unused" although it's not standard.
+ */
+
+int
+poll(struct pollfd *fds, nfds_t nfds, int timeout)
+{
+       nfds_t i;
+       int saved_errno, ret, fd, maxfd = 0;
+       fd_set *readfds = NULL, *writefds = NULL, *exceptfds = NULL;
+       size_t nmemb;
+       struct timeval tv, *tvp = NULL;
+
+       for (i = 0; i < nfds; i++) {
+               if (fd >= FD_SETSIZE) {
+                       errno = EINVAL;
+                       return -1;
+               }
+               maxfd = MAX(maxfd, fds[i].fd);
+       }
+
+       nmemb = howmany(maxfd + 1 , NFDBITS);
+       if ((readfds = calloc(nmemb, sizeof(fd_mask))) == NULL ||
+           (writefds = calloc(nmemb, sizeof(fd_mask))) == NULL ||
+           (exceptfds = calloc(nmemb, sizeof(fd_mask))) == NULL) {
+               saved_errno = ENOMEM;
+               ret = -1;
+               goto out;
+       }
+
+       /* populate event bit vectors for the events we're interested in */
+       for (i = 0; i < nfds; i++) {
+               fd = fds[i].fd;
+               if (fd == -1)
+                       continue;
+               if (fds[i].events & POLLIN) {
+                       FD_SET(fd, readfds);
+                       FD_SET(fd, exceptfds);
+               }
+               if (fds[i].events & POLLOUT) {
+                       FD_SET(fd, writefds);
+                       FD_SET(fd, exceptfds);
+               }
+       }
+
+       /* poll timeout is msec, select is timeval (sec + usec) */
+       if (timeout >= 0) {
+               tv.tv_sec = timeout / 1000;
+               tv.tv_usec = (timeout % 1000) * 1000;
+               tvp = &tv;
+       }
+
+       ret = select(maxfd + 1, readfds, writefds, exceptfds, tvp);
+       saved_errno = errno;
+
+       /* scan through select results and set poll() flags */
+       for (i = 0; i < nfds; i++) {
+               fd = fds[i].fd;
+               fds[i].revents = 0;
+               if (fd == -1)
+                       continue;
+               if (FD_ISSET(fd, readfds)) {
+                       fds[i].revents |= POLLIN;
+               }
+               if (FD_ISSET(fd, writefds)) {
+                       fds[i].revents |= POLLOUT;
+               }
+               if (FD_ISSET(fd, exceptfds)) {
+                       fds[i].revents |= POLLERR;
+               }
+       }
+
+out:
+       if (readfds != NULL)
+               free(readfds);
+       if (writefds != NULL)
+               free(writefds);
+       if (exceptfds != NULL)
+               free(exceptfds);
+       if (ret == -1)
+               errno = saved_errno;
+       return ret;
+}
+#endif
diff --git a/openbsd-compat/bsd-poll.h b/openbsd-compat/bsd-poll.h
new file mode 100644 (file)
index 0000000..dcbb9ca
--- /dev/null
@@ -0,0 +1,61 @@
+/*     $OpenBSD: poll.h,v 1.11 2003/12/10 23:10:08 millert Exp $ */
+
+/*
+ * Copyright (c) 1996 Theo de Raadt
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* OPENBSD ORIGINAL: sys/sys/poll.h */
+
+#if !defined(HAVE_POLL) && !defined(HAVE_POLL_H)
+#ifndef        _COMPAT_POLL_H_
+#define        _COMPAT_POLL_H_
+
+typedef struct pollfd {
+       int     fd;
+       short   events;
+       short   revents;
+} pollfd_t;
+
+typedef unsigned int   nfds_t;
+
+#define        POLLIN          0x0001
+#define        POLLOUT         0x0004
+#define        POLLERR         0x0008
+#if 0
+/* the following are currently not implemented */
+#define        POLLPRI         0x0002
+#define        POLLHUP         0x0010
+#define        POLLNVAL        0x0020
+#define        POLLRDNORM      0x0040
+#define POLLNORM       POLLRDNORM
+#define POLLWRNORM      POLLOUT
+#define        POLLRDBAND      0x0080
+#define        POLLWRBAND      0x0100
+#endif
+
+#define INFTIM         (-1)    /* not standard */
+
+int   poll(struct pollfd *, nfds_t, int);
+#endif /* !_COMPAT_POLL_H_ */
+#endif /* !HAVE_POLL_H */
index 6fe30fec83ec71f114af9959eac2a6219d7da64b..edf4b9dc255b820b6760e045ebc61f38f3a55b3c 100644 (file)
@@ -140,6 +140,7 @@ int writev(int, struct iovec *, int);
 /* Home grown routines */
 #include "bsd-misc.h"
 #include "bsd-waitpid.h"
+#include "bsd-poll.h"
 
 #ifndef HAVE_GETPEEREID
 int getpeereid(int , uid_t *, gid_t *);
This page took 0.060065 seconds and 5 git commands to generate.