mirror of
git://anongit.mindrot.org/openssh.git
synced 2024-12-27 20:42:07 +00:00
Add compat implementation of ppoll using pselect.
This commit is contained in:
parent
b544ce1ad4
commit
21dd5a9a3f
21
configure.ac
21
configure.ac
@ -1874,6 +1874,7 @@ AC_CHECK_FUNCS([ \
|
|||||||
openlog_r \
|
openlog_r \
|
||||||
pledge \
|
pledge \
|
||||||
poll \
|
poll \
|
||||||
|
ppoll \
|
||||||
prctl \
|
prctl \
|
||||||
procctl \
|
procctl \
|
||||||
pselect \
|
pselect \
|
||||||
@ -3547,6 +3548,26 @@ AC_RUN_IFELSE(
|
|||||||
select_works_with_rlimit=yes]
|
select_works_with_rlimit=yes]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
AC_CHECK_MEMBERS([struct pollfd.fd], [], [], [[
|
||||||
|
#include <sys/types.h>
|
||||||
|
#ifdef HAVE_POLL_H
|
||||||
|
#include <poll.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_POLL_H
|
||||||
|
#include <sys/poll.h>
|
||||||
|
#endif
|
||||||
|
]])
|
||||||
|
|
||||||
|
AC_CHECK_TYPES([nfds_t], , , [
|
||||||
|
#include <sys/types.h>
|
||||||
|
#ifdef HAVE_POLL_H
|
||||||
|
#include <poll.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_POLL_H
|
||||||
|
#include <sys/poll.h>
|
||||||
|
#endif
|
||||||
|
])
|
||||||
|
|
||||||
AC_MSG_CHECKING([if setrlimit(RLIMIT_NOFILE,{0,0}) works])
|
AC_MSG_CHECKING([if setrlimit(RLIMIT_NOFILE,{0,0}) works])
|
||||||
AC_RUN_IFELSE(
|
AC_RUN_IFELSE(
|
||||||
[AC_LANG_PROGRAM([[
|
[AC_LANG_PROGRAM([[
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
#if !defined(HAVE_POLL)
|
#if !defined(HAVE_PPOLL) || !defined(HAVE_POLL)
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
@ -24,12 +24,14 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "bsd-poll.h"
|
#include "bsd-poll.h"
|
||||||
|
|
||||||
|
#ifndef HAVE_PPOLL
|
||||||
/*
|
/*
|
||||||
* A minimal implementation of poll(2), built on top of select(2).
|
* A minimal implementation of ppoll(2), built on top of pselect(2).
|
||||||
*
|
*
|
||||||
* Only supports POLLIN and POLLOUT flags in pfd.events, and POLLIN, POLLOUT
|
* Only supports POLLIN and POLLOUT flags in pfd.events, and POLLIN, POLLOUT
|
||||||
* and POLLERR flags in revents.
|
* and POLLERR flags in revents.
|
||||||
@ -38,13 +40,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
int
|
int
|
||||||
poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmoutp,
|
||||||
|
const sigset_t *sigmask)
|
||||||
{
|
{
|
||||||
nfds_t i;
|
nfds_t i;
|
||||||
int saved_errno, ret, fd, maxfd = 0;
|
int saved_errno, ret, fd, maxfd = 0;
|
||||||
fd_set *readfds = NULL, *writefds = NULL, *exceptfds = NULL;
|
fd_set *readfds = NULL, *writefds = NULL, *exceptfds = NULL;
|
||||||
size_t nmemb;
|
size_t nmemb;
|
||||||
struct timeval tv, *tvp = NULL;
|
|
||||||
|
|
||||||
for (i = 0; i < nfds; i++) {
|
for (i = 0; i < nfds; i++) {
|
||||||
fd = fds[i].fd;
|
fd = fds[i].fd;
|
||||||
@ -79,14 +81,7 @@ poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* poll timeout is msec, select is timeval (sec + usec) */
|
ret = pselect(maxfd + 1, readfds, writefds, exceptfds, tmoutp, sigmask);
|
||||||
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;
|
saved_errno = errno;
|
||||||
|
|
||||||
/* scan through select results and set poll() flags */
|
/* scan through select results and set poll() flags */
|
||||||
@ -114,4 +109,23 @@ out:
|
|||||||
errno = saved_errno;
|
errno = saved_errno;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* HAVE_PPOLL */
|
||||||
|
|
||||||
|
#ifdef HAVE_POLL
|
||||||
|
int
|
||||||
|
poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
||||||
|
{
|
||||||
|
struct timespec ts, *tsp = NULL;
|
||||||
|
|
||||||
|
/* poll timeout is msec, ppoll is timespec (sec + nsec) */
|
||||||
|
if (timeout >= 0) {
|
||||||
|
ts.tv_sec = timeout / 1000;
|
||||||
|
ts.tv_nsec = (timeout % 1000000) * 1000000;
|
||||||
|
tsp = &ts;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ppoll(fds, nfds, tsp, NULL);
|
||||||
|
}
|
||||||
|
#endif /* HAVE_POLL */
|
||||||
|
|
||||||
|
#endif /* HAVE_PPOLL || HAVE_POLL */
|
||||||
|
@ -27,18 +27,24 @@
|
|||||||
|
|
||||||
/* OPENBSD ORIGINAL: sys/sys/poll.h */
|
/* OPENBSD ORIGINAL: sys/sys/poll.h */
|
||||||
|
|
||||||
#if !defined(HAVE_POLL) && !defined(HAVE_POLL_H)
|
|
||||||
#ifndef _COMPAT_POLL_H_
|
#ifndef _COMPAT_POLL_H_
|
||||||
#define _COMPAT_POLL_H_
|
#define _COMPAT_POLL_H_
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#ifdef HAVE_POLL_H
|
||||||
|
# include <poll.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_POLL_H
|
||||||
|
# include <sys/poll.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_STRUCT_POLLFD_FD
|
||||||
typedef struct pollfd {
|
typedef struct pollfd {
|
||||||
int fd;
|
int fd;
|
||||||
short events;
|
short events;
|
||||||
short revents;
|
short revents;
|
||||||
} pollfd_t;
|
} pollfd_t;
|
||||||
|
|
||||||
typedef unsigned int nfds_t;
|
|
||||||
|
|
||||||
#define POLLIN 0x0001
|
#define POLLIN 0x0001
|
||||||
#define POLLOUT 0x0004
|
#define POLLOUT 0x0004
|
||||||
#define POLLERR 0x0008
|
#define POLLERR 0x0008
|
||||||
@ -55,7 +61,18 @@ typedef unsigned int nfds_t;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define INFTIM (-1) /* not standard */
|
#define INFTIM (-1) /* not standard */
|
||||||
|
#endif /* !HAVE_STRUCT_POLLFD_FD */
|
||||||
|
|
||||||
|
#ifndef HAVE_NFDS_T
|
||||||
|
typedef unsigned int nfds_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_POLL
|
||||||
int poll(struct pollfd *, nfds_t, int);
|
int poll(struct pollfd *, nfds_t, int);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_PPOLL
|
||||||
|
int ppoll(struct pollfd *, nfds_t, const struct timespec *, const sigset_t *);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* !_COMPAT_POLL_H_ */
|
#endif /* !_COMPAT_POLL_H_ */
|
||||||
#endif /* !HAVE_POLL_H */
|
|
||||||
|
Loading…
Reference in New Issue
Block a user