This patch adds a poll() replacement to OpenNTPD's compat library,  built
around select().  It (should :-) allow OpenNTPD to work on platforms
that have select() but not poll(), eg QNX4.

You will need to run "autoreconf" to rebuild configure after applying
the patch, then ./configure && make as normal.

Index: configure.ac
===================================================================
RCS file: /usr/local/cvs/openntpd-portable/configure.ac,v
retrieving revision 1.50
diff -u -p -r1.50 configure.ac
--- configure.ac	14 Dec 2004 00:55:36 -0000	1.50
+++ configure.ac	16 Dec 2004 06:07:33 -0000
@@ -70,9 +70,9 @@ case "$host" in
 	;;
 esac
 
-AC_CHECK_HEADERS(arpa/inet.h ctype.h ifaddrs.h netdb.h paths.h stdarg.h \
-	sys/bitypes.h sys/fcntl.h sys/queue.h sys/time.h sys/socket.h \
-	sys/timex.h sys/types.h syslog.h)
+AC_CHECK_HEADERS(arpa/inet.h ctype.h ifaddrs.h netdb.h paths.h poll.h stdarg.h \
+	sys/bitypes.h sys/fcntl.h sys/queue.h sys/select.h sys/time.h \
+	sys/socket.h sys/timex.h sys/types.h syslog.h)
 
 AC_CHECK_DECLS(asprintf, ,
 	[saved_CFLAGS="$CFLAGS"
@@ -91,7 +91,8 @@ AC_CHECK_FUNCS(socketpair, ,
 )
 
 AC_CHECK_FUNCS(adjtimex arc4random asprintf bzero clock_getres daemon \
-	getifaddrs inet_pton setproctitle snprintf strlcpy vsnprintf vsyslog)
+	getifaddrs inet_pton poll select setproctitle snprintf strlcpy \
+	vsnprintf vsyslog)
 
 dnl Check for uidswap functions
 AC_CHECK_FUNCS(setuid setgid seteuid setegid setreuid setregid \
Index: ntp.c
===================================================================
RCS file: /usr/local/cvs/openntpd-portable/ntp.c,v
retrieving revision 1.27
diff -u -p -r1.27 ntp.c
--- ntp.c	14 Dec 2004 01:23:23 -0000	1.27
+++ ntp.c	16 Dec 2004 07:03:27 -0000
@@ -17,6 +17,8 @@
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include "includes.h"
+
 #include <sys/param.h>
 #include <sys/time.h>
 #include <sys/stat.h>
@@ -25,7 +27,9 @@
 #ifdef HAVE_PATHS_H
 # include <paths.h>
 #endif
-#include <poll.h>
+#ifdef HAVE_POLL_H
+# include <poll.h>
+#endif
 #include <pwd.h>
 #include <signal.h>
 #include <stdlib.h>
Index: ntpd.c
===================================================================
RCS file: /usr/local/cvs/openntpd-portable/ntpd.c,v
retrieving revision 1.27
diff -u -p -r1.27 ntpd.c
--- ntpd.c	15 Dec 2004 01:18:46 -0000	1.27
+++ ntpd.c	16 Dec 2004 01:21:48 -0000
@@ -27,7 +27,9 @@ RCSID("$Release: OpenNTPD "OPENNTPD_VERS
 #include <arpa/inet.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <poll.h>
+#ifdef HAVE_POLL_H
+# include <poll.h>
+#endif
 #include <pwd.h>
 #include <signal.h>
 #include <stdio.h>
Index: openbsd-compat/Makefile.in
===================================================================
RCS file: /usr/local/cvs/openntpd-portable/openbsd-compat/Makefile.in,v
retrieving revision 1.7
diff -u -p -r1.7 Makefile.in
--- openbsd-compat/Makefile.in	26 Oct 2004 10:55:05 -0000	1.7
+++ openbsd-compat/Makefile.in	16 Dec 2004 04:36:37 -0000
@@ -7,7 +7,8 @@ top_srcdir=@top_srcdir@
 all:	libopenbsd-compat.a
 
 OPENBSD=	asprintf.o daemon.o inet_pton.o strlcpy.o
-COMPAT=		bsd-arc4random.o bsd-misc.o bsd-snprintf.o fake-rfc2553.o \
+COMPAT=		bsd-arc4random.o bsd-misc.o bsd-poll.o bsd-snprintf.o \
+		 fake-rfc2553.o \
 		uidswap.o
 
 VPATH=@srcdir@
Index: openbsd-compat/bsd-poll.c
===================================================================
RCS file: openbsd-compat/bsd-poll.c
diff -N openbsd-compat/bsd-poll.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openbsd-compat/bsd-poll.c	16 Dec 2004 06:58:16 -0000
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2004 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"
+
+int
+poll(struct pollfd *fds, nfds_t nfds, int timeout)
+{
+	nfds_t i;
+	int ret, fd, maxfd = 0;
+	fd_set readfds, writefds, exceptfds;
+	struct timeval tv, *tvp = NULL;
+
+	if (nfds > FD_SETSIZE) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	FD_ZERO(&readfds);
+	FD_ZERO(&writefds);
+	FD_ZERO(&exceptfds);
+
+	/* poll timeout is msec, select is timeval (sec + usec) */
+	if (timeout != INFTIM) {
+		tv.tv_sec = timeout / 1000;
+		tv.tv_usec = (timeout % 1000) * 1000 * 1000;
+		tvp = &tv;
+	}
+
+	/* populate event bit vectors for the events we're interested in */
+	for (i = 0; i < nfds; i++) {
+		fd = fds[i].fd;
+		maxfd = MAX(maxfd, fd);
+		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);
+		}
+	}
+
+	ret = select(maxfd + 1, &readfds, &writefds, &exceptfds, tvp);
+
+	/* scan through select results and set poll() flags */
+	for (i = 0; i < nfds; i++) {
+		fd = fds[i].fd;
+		fds[i].revents = 0;
+		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;
+		}
+	}
+	return ret;
+}
+#endif
Index: openbsd-compat/bsd-poll.h
===================================================================
RCS file: openbsd-compat/bsd-poll.h
diff -N openbsd-compat/bsd-poll.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openbsd-compat/bsd-poll.h	16 Dec 2004 07:00:05 -0000
@@ -0,0 +1,56 @@
+/*	$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.
+ */
+
+#ifndef 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	POLLPRI		0x0002
+#define	POLLOUT		0x0004
+#define	POLLERR		0x0008
+#define	POLLHUP		0x0010
+#define	POLLNVAL	0x0020
+#define	POLLRDNORM	0x0040
+#define POLLNORM	POLLRDNORM
+#define POLLWRNORM      POLLOUT
+#define	POLLRDBAND	0x0080
+#define	POLLWRBAND	0x0100
+
+#define INFTIM		(-1)
+
+int   poll(struct pollfd *, nfds_t, int);
+#endif /* !_COMPAT_POLL_H_ */
+#endif /* !HAVE_POLL_H */
Index: openbsd-compat/openbsd-compat.h
===================================================================
RCS file: /usr/local/cvs/openntpd-portable/openbsd-compat/openbsd-compat.h,v
retrieving revision 1.13
diff -u -p -r1.13 openbsd-compat.h
--- openbsd-compat/openbsd-compat.h	15 Dec 2004 15:21:49 -0000	1.13
+++ openbsd-compat/openbsd-compat.h	16 Dec 2004 04:38:13 -0000
@@ -20,6 +20,7 @@
 #include <netdb.h>
 
 #include "fake-rfc2553.h"
+#include "bsd-poll.h"
 
 char *_compat_get_progname(char *);
 
