]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/sigtimedwait.c
Function declaration cleanup
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / sigtimedwait.c
CommitLineData
b168057a 1/* Copyright (C) 1997-2015 Free Software Foundation, Inc.
cbdee279
UD
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
cbdee279
UD
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 12 Lesser General Public License for more details.
cbdee279 13
41bdb6e2 14 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
cbdee279 17
0dee6738 18#include <errno.h>
cbdee279 19#include <signal.h>
6080ecdf 20#include <string.h>
cbdee279 21
08192659 22#include <nptl/pthreadP.h>
6ee8d334 23#include <sysdep-cancel.h>
0dee6738
UD
24#include <sys/syscall.h>
25
655b26bb 26#ifdef __NR_rt_sigtimedwait
cbdee279 27
bc58c14e
UD
28static int
29do_sigtimedwait (const sigset_t *set, siginfo_t *info,
30 const struct timespec *timeout)
31{
aa3cee21
UD
32#ifdef SIGCANCEL
33 sigset_t tmpset;
53b4fed6
UD
34 if (set != NULL
35 && (__builtin_expect (__sigismember (set, SIGCANCEL), 0)
36# ifdef SIGSETXID
37 || __builtin_expect (__sigismember (set, SIGSETXID), 0)
38# endif
39 ))
aa3cee21
UD
40 {
41 /* Create a temporary mask without the bit for SIGCANCEL set. */
42 // We are not copying more than we have to.
43 memcpy (&tmpset, set, _NSIG / 8);
44 __sigdelset (&tmpset, SIGCANCEL);
53b4fed6
UD
45# ifdef SIGSETXID
46 __sigdelset (&tmpset, SIGSETXID);
47# endif
aa3cee21
UD
48 set = &tmpset;
49 }
50#endif
51
bc58c14e
UD
52 /* XXX The size argument hopefully will have to be changed to the
53 real size of the user-level sigset_t. */
32a45bea 54 int result = INLINE_SYSCALL (rt_sigtimedwait, 4, set,
f3aae3f3 55 info, timeout, _NSIG / 8);
bc58c14e
UD
56
57 /* The kernel generates a SI_TKILL code in si_code in case tkill is
58 used. tkill is transparently used in raise(). Since having
59 SI_TKILL as a code is useful in general we fold the results
60 here. */
61 if (result != -1 && info != NULL && info->si_code == SI_TKILL)
62 info->si_code = SI_USER;
63
64 return result;
65}
66
67
cbdee279
UD
68/* Return any pending signal or wait for one for the given time. */
69int
14bb4e57
AZ
70__sigtimedwait (const sigset_t *set, siginfo_t *info,
71 const struct timespec *timeout)
cbdee279 72{
6ee8d334 73 if (SINGLE_THREAD_P)
bc58c14e 74 return do_sigtimedwait (set, info, timeout);
6ee8d334
UD
75
76 int oldtype = LIBC_CANCEL_ASYNC ();
77
cbdee279
UD
78 /* XXX The size argument hopefully will have to be changed to the
79 real size of the user-level sigset_t. */
bc58c14e 80 int result = do_sigtimedwait (set, info, timeout);
6ee8d334
UD
81
82 LIBC_CANCEL_RESET (oldtype);
83
84 return result;
cbdee279 85}
6166815d 86libc_hidden_def (__sigtimedwait)
cbdee279 87weak_alias (__sigtimedwait, sigtimedwait)
655b26bb 88#else
2826ac7e 89# include <signal/sigtimedwait.c>
655b26bb 90#endif