]>
Commit | Line | Data |
---|---|---|
04277e02 | 1 | /* Copyright (C) 1996-2019 Free Software Foundation, Inc. |
478b92f0 UD |
2 | This file is part of the GNU C Library. |
3 | Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. | |
503054c0 | 4 | |
478b92f0 | 5 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
503054c0 | 9 | |
478b92f0 UD |
10 | The GNU C Library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
503054c0 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
503054c0 RM |
18 | |
19 | #include <errno.h> | |
cb0509a8 | 20 | #include <signal.h> |
8be918b7 | 21 | #include <stddef.h> /* For NULL. */ |
842907c6 | 22 | #include <sys/time.h> |
503054c0 | 23 | #include <sys/select.h> |
93c04024 | 24 | #include <sysdep-cancel.h> |
b59b200e | 25 | |
503054c0 RM |
26 | |
27 | /* Check the first NFDS descriptors each in READFDS (if not NULL) for read | |
28 | readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS | |
29 | (if not NULL) for exceptional conditions. If TIMEOUT is not NULL, time out | |
cb0509a8 UD |
30 | after waiting the interval specified therein. Additionally set the sigmask |
31 | SIGMASK for this call. Returns the number of ready descriptors, or -1 for | |
32 | errors. */ | |
814ef022 | 33 | int |
b59b200e UD |
34 | __pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, |
35 | const struct timespec *timeout, const sigset_t *sigmask) | |
503054c0 RM |
36 | { |
37 | struct timeval tval; | |
38 | int retval; | |
cb0509a8 | 39 | sigset_t savemask; |
503054c0 | 40 | |
db7ffaa3 | 41 | /* Change nanosecond number to microseconds. This might mean losing |
503054c0 RM |
42 | precision and therefore the `pselect` should be available. But |
43 | for now it is hardly found. */ | |
44 | if (timeout != NULL) | |
68a3f91f UD |
45 | { |
46 | /* Catch bugs which would be hidden by the TIMESPEC_TO_TIMEVAL | |
47 | computations. The division by 1000 truncates values. */ | |
a1ffb40e | 48 | if (__glibc_unlikely (timeout->tv_nsec < 0)) |
68a3f91f UD |
49 | { |
50 | __set_errno (EINVAL); | |
51 | return -1; | |
52 | } | |
53 | ||
54 | TIMESPEC_TO_TIMEVAL (&tval, timeout); | |
55 | } | |
503054c0 | 56 | |
cb0509a8 UD |
57 | /* The setting and restoring of the signal mask and the select call |
58 | should be an atomic operation. This can't be done without kernel | |
59 | help. */ | |
db7ffaa3 UD |
60 | if (sigmask != NULL) |
61 | __sigprocmask (SIG_SETMASK, sigmask, &savemask); | |
62 | ||
7a114794 UD |
63 | /* Note the pselect() is a cancellation point. But since we call |
64 | select() which itself is a cancellation point we do not have | |
65 | to do anything here. */ | |
503054c0 RM |
66 | retval = __select (nfds, readfds, writefds, exceptfds, |
67 | timeout != NULL ? &tval : NULL); | |
db7ffaa3 UD |
68 | |
69 | if (sigmask != NULL) | |
70 | __sigprocmask (SIG_SETMASK, &savemask, NULL); | |
503054c0 RM |
71 | |
72 | return retval; | |
73 | } | |
7c65e900 | 74 | #ifndef __pselect |
503054c0 | 75 | weak_alias (__pselect, pselect) |
7c65e900 | 76 | #endif |