2012-06-22 21:26:37 +00:00
|
|
|
/* pselect - synchronous I/O multiplexing
|
|
|
|
|
2024-01-02 01:47:10 +00:00
|
|
|
Copyright 2011-2024 Free Software Foundation, Inc.
|
2012-06-22 21:26:37 +00:00
|
|
|
|
|
|
|
This file is part of gnulib.
|
|
|
|
|
Update from Gnulib
Make the following changes by hand, and run 'admin/merge-gnulib'.
* .gitignore: Add lib/malloc/*.gl.h.
* admin/merge-gnulib: Copy lib/af_alg.h and lib/save-cwd.h
directly from Gnulib, without worrying about Gnulib modules,
as these files are special cases.
(AVOIDED_MODULES): Remove malloc-posix.
* lib/malloc.c, lib/realloc.c, m4/malloc.m4, m4/realloc.m4:
* m4/year2038.m4: New files, copied from Gnulib.
* lib/malloca.c, lib/malloca.h:
* m4/close-stream.m4, m4/glibc21.m4, m4/malloca.m4:
Remove. These are either no longer present in Gnulib, or are no
longer needed by modules that Emacs uses.
* oldXMenu/AddPane.c, oldXmenu/Addsel.c: Include XmenuInt.h first;
needed for new Gnulib.
* src/xmenu.c: Call emacs_abort, not abort.
2021-10-04 19:11:39 +00:00
|
|
|
This file is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as
|
|
|
|
published by the Free Software Foundation; either version 2.1 of the
|
|
|
|
License, or (at your option) any later version.
|
2012-06-22 21:26:37 +00:00
|
|
|
|
Update from Gnulib
Make the following changes by hand, and run 'admin/merge-gnulib'.
* .gitignore: Add lib/malloc/*.gl.h.
* admin/merge-gnulib: Copy lib/af_alg.h and lib/save-cwd.h
directly from Gnulib, without worrying about Gnulib modules,
as these files are special cases.
(AVOIDED_MODULES): Remove malloc-posix.
* lib/malloc.c, lib/realloc.c, m4/malloc.m4, m4/realloc.m4:
* m4/year2038.m4: New files, copied from Gnulib.
* lib/malloca.c, lib/malloca.h:
* m4/close-stream.m4, m4/glibc21.m4, m4/malloca.m4:
Remove. These are either no longer present in Gnulib, or are no
longer needed by modules that Emacs uses.
* oldXMenu/AddPane.c, oldXmenu/Addsel.c: Include XmenuInt.h first;
needed for new Gnulib.
* src/xmenu.c: Call emacs_abort, not abort.
2021-10-04 19:11:39 +00:00
|
|
|
This file is distributed in the hope that it will be useful,
|
2012-06-22 21:26:37 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Update from Gnulib
Make the following changes by hand, and run 'admin/merge-gnulib'.
* .gitignore: Add lib/malloc/*.gl.h.
* admin/merge-gnulib: Copy lib/af_alg.h and lib/save-cwd.h
directly from Gnulib, without worrying about Gnulib modules,
as these files are special cases.
(AVOIDED_MODULES): Remove malloc-posix.
* lib/malloc.c, lib/realloc.c, m4/malloc.m4, m4/realloc.m4:
* m4/year2038.m4: New files, copied from Gnulib.
* lib/malloca.c, lib/malloca.h:
* m4/close-stream.m4, m4/glibc21.m4, m4/malloca.m4:
Remove. These are either no longer present in Gnulib, or are no
longer needed by modules that Emacs uses.
* oldXMenu/AddPane.c, oldXmenu/Addsel.c: Include XmenuInt.h first;
needed for new Gnulib.
* src/xmenu.c: Call emacs_abort, not abort.
2021-10-04 19:11:39 +00:00
|
|
|
GNU Lesser General Public License for more details.
|
2012-06-22 21:26:37 +00:00
|
|
|
|
Update from Gnulib
Make the following changes by hand, and run 'admin/merge-gnulib'.
* .gitignore: Add lib/malloc/*.gl.h.
* admin/merge-gnulib: Copy lib/af_alg.h and lib/save-cwd.h
directly from Gnulib, without worrying about Gnulib modules,
as these files are special cases.
(AVOIDED_MODULES): Remove malloc-posix.
* lib/malloc.c, lib/realloc.c, m4/malloc.m4, m4/realloc.m4:
* m4/year2038.m4: New files, copied from Gnulib.
* lib/malloca.c, lib/malloca.h:
* m4/close-stream.m4, m4/glibc21.m4, m4/malloca.m4:
Remove. These are either no longer present in Gnulib, or are no
longer needed by modules that Emacs uses.
* oldXMenu/AddPane.c, oldXmenu/Addsel.c: Include XmenuInt.h first;
needed for new Gnulib.
* src/xmenu.c: Call emacs_abort, not abort.
2021-10-04 19:11:39 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
2012-06-22 21:26:37 +00:00
|
|
|
|
|
|
|
/* written by Paul Eggert */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <sys/select.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
/* Examine the size-NFDS file descriptor sets in RFDS, WFDS, and XFDS
|
|
|
|
to see whether some of their descriptors are ready for reading,
|
|
|
|
ready for writing, or have exceptions pending. Wait for at most
|
|
|
|
TIMEOUT seconds, and use signal mask SIGMASK while waiting. A null
|
|
|
|
pointer parameter stands for no descriptors, an infinite timeout,
|
|
|
|
or an unaffected signal mask. */
|
|
|
|
|
2012-10-04 07:15:42 +00:00
|
|
|
#if !HAVE_PSELECT
|
|
|
|
|
2012-06-22 21:26:37 +00:00
|
|
|
int
|
|
|
|
pselect (int nfds, fd_set *restrict rfds,
|
|
|
|
fd_set *restrict wfds, fd_set *restrict xfds,
|
|
|
|
struct timespec const *restrict timeout,
|
|
|
|
sigset_t const *restrict sigmask)
|
|
|
|
{
|
|
|
|
int select_result;
|
|
|
|
sigset_t origmask;
|
|
|
|
struct timeval tv, *tvp;
|
|
|
|
|
2023-05-15 01:51:22 +00:00
|
|
|
if (nfds < 0 || nfds > FD_SETSIZE)
|
|
|
|
{
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-06-22 21:26:37 +00:00
|
|
|
if (timeout)
|
|
|
|
{
|
|
|
|
if (! (0 <= timeout->tv_nsec && timeout->tv_nsec < 1000000000))
|
|
|
|
{
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2023-05-16 05:09:04 +00:00
|
|
|
tv = (struct timeval) {
|
|
|
|
.tv_sec = timeout->tv_sec,
|
|
|
|
.tv_usec = (timeout->tv_nsec + 999) / 1000
|
|
|
|
};
|
2012-06-22 21:26:37 +00:00
|
|
|
tvp = &tv;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tvp = NULL;
|
|
|
|
|
|
|
|
/* Signal mask munging should be atomic, but this is the best we can
|
|
|
|
do in this emulation. */
|
|
|
|
if (sigmask)
|
|
|
|
pthread_sigmask (SIG_SETMASK, sigmask, &origmask);
|
|
|
|
|
|
|
|
select_result = select (nfds, rfds, wfds, xfds, tvp);
|
|
|
|
|
|
|
|
if (sigmask)
|
|
|
|
{
|
|
|
|
int select_errno = errno;
|
|
|
|
pthread_sigmask (SIG_SETMASK, &origmask, NULL);
|
|
|
|
errno = select_errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
return select_result;
|
|
|
|
}
|
2012-10-04 07:15:42 +00:00
|
|
|
|
|
|
|
#else /* HAVE_PSELECT */
|
|
|
|
# include <unistd.h>
|
|
|
|
# undef pselect
|
|
|
|
|
|
|
|
int
|
|
|
|
rpl_pselect (int nfds, fd_set *restrict rfds,
|
Update from Gnulib
This incorporates:
2018-06-29 regex: glibc does not use intprops.h
2018-06-28 regex: port to recently proposed glibc regex merge
2018-06-25 Continue to use spaces for indentation, not tabs
2018-06-25 manywarnings: Don't enable -Wjump-misses-init by default
2018-06-25 acl-internal.h: remove _GL_ATTRIBUTE_CONST on void function
2018-06-24 manywarnings: accommodate GCC 9: remove -Wchkp and -Wabi
2018-06-24 maint: clarify comments about sticky EOF
2018-06-24 af_alg: avoid hangs when reading from streams
2018-06-17 crypto: use byteswap
2018-06-17 getloadavg: Return 0 on MS-Windows without Cygwi
2018-06-17 getloadavg: Allow building on MS-Windows without Cygwin
* build-aux/config.guess, build-aux/config.sub, doc/misc/texinfo.tex:
* lib/acl-internal.c, lib/acl-internal.h, lib/get-permissions.c:
* lib/getloadavg.c, lib/gettimeofday.c, lib/md5.c, lib/pselect.c:
* lib/set-permissions.c, lib/sha1.c, lib/sha256.c, lib/sha512.c:
* lib/time.in.h, m4/getloadavg.m4, m4/gnulib-common.m4:
* m4/manywarnings.m4, m4/pthread_sigmask.m4, m4/vararrays.m4:
Copy from Gnulib.
2018-06-30 00:31:04 +00:00
|
|
|
fd_set *restrict wfds, fd_set *restrict xfds,
|
2012-10-04 07:15:42 +00:00
|
|
|
struct timespec const *restrict timeout,
|
Update from Gnulib
This incorporates:
2018-06-29 regex: glibc does not use intprops.h
2018-06-28 regex: port to recently proposed glibc regex merge
2018-06-25 Continue to use spaces for indentation, not tabs
2018-06-25 manywarnings: Don't enable -Wjump-misses-init by default
2018-06-25 acl-internal.h: remove _GL_ATTRIBUTE_CONST on void function
2018-06-24 manywarnings: accommodate GCC 9: remove -Wchkp and -Wabi
2018-06-24 maint: clarify comments about sticky EOF
2018-06-24 af_alg: avoid hangs when reading from streams
2018-06-17 crypto: use byteswap
2018-06-17 getloadavg: Return 0 on MS-Windows without Cygwi
2018-06-17 getloadavg: Allow building on MS-Windows without Cygwin
* build-aux/config.guess, build-aux/config.sub, doc/misc/texinfo.tex:
* lib/acl-internal.c, lib/acl-internal.h, lib/get-permissions.c:
* lib/getloadavg.c, lib/gettimeofday.c, lib/md5.c, lib/pselect.c:
* lib/set-permissions.c, lib/sha1.c, lib/sha256.c, lib/sha512.c:
* lib/time.in.h, m4/getloadavg.m4, m4/gnulib-common.m4:
* m4/manywarnings.m4, m4/pthread_sigmask.m4, m4/vararrays.m4:
Copy from Gnulib.
2018-06-30 00:31:04 +00:00
|
|
|
sigset_t const *restrict sigmask)
|
2012-10-04 07:15:42 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* FreeBSD 8.2 has a bug: it does not always detect invalid fds. */
|
|
|
|
if (nfds < 0 || nfds > FD_SETSIZE)
|
|
|
|
{
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
for (i = 0; i < nfds; i++)
|
|
|
|
{
|
|
|
|
if (((rfds && FD_ISSET (i, rfds))
|
|
|
|
|| (wfds && FD_ISSET (i, wfds))
|
|
|
|
|| (xfds && FD_ISSET (i, xfds)))
|
|
|
|
&& dup2 (i, i) != i)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pselect (nfds, rfds, wfds, xfds, timeout, sigmask);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|