Update copyright dates with scripts/update-copyrights.
[glibc.git] / sysdeps / mach / hurd / sigprocmask.c
blob2e496dc63bcd8c1a5cad97c759bd47425d1218f2
1 /* Copyright (C) 1991-2015 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
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.
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
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
18 #include <errno.h>
19 #include <signal.h>
20 #include <hurd.h>
21 #include <hurd/signal.h>
22 #include <hurd/msg.h>
24 /* If SET is not NULL, modify the current set of blocked signals
25 according to HOW, which may be SIG_BLOCK, SIG_UNBLOCK or SIG_SETMASK.
26 If OSET is not NULL, store the old set of blocked signals in *OSET. */
27 int
28 __sigprocmask (how, set, oset)
29 int how;
30 const sigset_t *set;
31 sigset_t *oset;
33 struct hurd_sigstate *ss;
34 sigset_t old, new;
35 sigset_t pending;
37 if (set != NULL)
38 new = *set;
40 ss = _hurd_self_sigstate ();
42 __spin_lock (&ss->lock);
44 old = ss->blocked;
46 if (set != NULL)
48 switch (how)
50 case SIG_BLOCK:
51 __sigorset (&ss->blocked, &ss->blocked, &new);
52 break;
54 case SIG_UNBLOCK:
55 ss->blocked &= ~new;
56 break;
58 case SIG_SETMASK:
59 ss->blocked = new;
60 break;
62 default:
63 __spin_unlock (&ss->lock);
64 errno = EINVAL;
65 return -1;
68 ss->blocked &= ~_SIG_CANT_MASK;
71 pending = ss->pending & ~ss->blocked;
73 __spin_unlock (&ss->lock);
75 if (oset != NULL)
76 *oset = old;
78 if (pending)
79 /* Send a message to the signal thread so it
80 will wake up and check for pending signals. */
81 __msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ());
83 return 0;
86 weak_alias (__sigprocmask, sigprocmask)