]>
Commit | Line | Data |
---|---|---|
33574c17 | 1 | /* Set a thread's signal state. Hurd on Mach version. |
6d7e8eda | 2 | Copyright (C) 2002-2023 Free Software Foundation, Inc. |
33574c17 ST |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
ad2b41bf ST |
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. | |
33574c17 ST |
9 | |
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 | |
ad2b41bf | 13 | Lesser General Public License for more details. |
33574c17 | 14 | |
ad2b41bf ST |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with the GNU C Library; if not, see | |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
33574c17 ST |
18 | |
19 | #include <pthread.h> | |
20 | #include <assert.h> | |
21 | #include <signal.h> | |
22 | #include <hurd/signal.h> | |
653d74f1 | 23 | #include <hurd/msg.h> |
33574c17 ST |
24 | |
25 | #include <pt-internal.h> | |
26 | ||
27 | error_t | |
28 | __pthread_sigstate (struct __pthread *thread, int how, | |
29 | const sigset_t *set, sigset_t *oset, int clear_pending) | |
30 | { | |
31 | error_t err = 0; | |
32 | struct hurd_sigstate *ss; | |
1cc205c5 | 33 | sigset_t old, new; |
653d74f1 | 34 | sigset_t pending; |
33574c17 | 35 | |
1cc205c5 ST |
36 | if (set != NULL) |
37 | new = *set; | |
38 | ||
33574c17 ST |
39 | ss = _hurd_thread_sigstate (thread->kernel_thread); |
40 | assert (ss); | |
41 | ||
653d74f1 | 42 | _hurd_sigstate_lock (ss); |
33574c17 | 43 | |
1cc205c5 | 44 | old = ss->blocked; |
33574c17 ST |
45 | |
46 | if (set != NULL) | |
47 | { | |
48 | switch (how) | |
49 | { | |
50 | case SIG_BLOCK: | |
1cc205c5 | 51 | ss->blocked |= new; |
33574c17 ST |
52 | break; |
53 | ||
54 | case SIG_SETMASK: | |
1cc205c5 | 55 | ss->blocked = new; |
33574c17 ST |
56 | break; |
57 | ||
58 | case SIG_UNBLOCK: | |
1cc205c5 | 59 | ss->blocked &= ~new; |
33574c17 ST |
60 | break; |
61 | ||
62 | default: | |
63 | err = EINVAL; | |
64 | break; | |
65 | } | |
66 | ss->blocked &= ~_SIG_CANT_MASK; | |
67 | } | |
68 | ||
69 | if (!err && clear_pending) | |
70 | __sigemptyset (&ss->pending); | |
71 | ||
653d74f1 JK |
72 | pending = _hurd_sigstate_pending (ss) & ~ss->blocked; |
73 | _hurd_sigstate_unlock (ss); | |
74 | ||
1cc205c5 ST |
75 | if (!err && oset != NULL) |
76 | *oset = old; | |
77 | ||
653d74f1 JK |
78 | if (!err && 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 ()); | |
33574c17 ST |
82 | |
83 | return err; | |
84 | } |