]>
Commit | Line | Data |
---|---|---|
df4ef2ab | 1 | /* BSD-like signal function. |
6d7e8eda | 2 | Copyright (C) 1991-2023 Free Software Foundation, Inc. |
84384f5b | 3 | This file is part of the GNU C Library. |
28f540f4 | 4 | |
84384f5b | 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. | |
28f540f4 | 9 | |
84384f5b 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. |
28f540f4 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
28f540f4 | 18 | |
28f540f4 RM |
19 | #include <errno.h> |
20 | #include <signal.h> | |
a992f506 | 21 | #include <sigsetops.h> |
d2dc5467 | 22 | #include <internal-signals.h> |
28f540f4 | 23 | |
1897bc3f | 24 | sigset_t _sigintr attribute_hidden; /* Set by siginterrupt. */ |
df4ef2ab | 25 | |
28f540f4 RM |
26 | /* Set the handler for the signal SIG to HANDLER, |
27 | returning the old handler, or SIG_ERR on error. */ | |
28 | __sighandler_t | |
bd2260a2 | 29 | __bsd_signal (int sig, __sighandler_t handler) |
28f540f4 RM |
30 | { |
31 | struct sigaction act, oact; | |
32 | ||
84384f5b | 33 | /* Check signal extents to protect __sigismember. */ |
d2dc5467 | 34 | if (handler == SIG_ERR || sig < 1 || sig >= NSIG |
a1bdd816 | 35 | || is_internal_signal (sig)) |
28f540f4 | 36 | { |
c4029823 | 37 | __set_errno (EINVAL); |
28f540f4 RM |
38 | return SIG_ERR; |
39 | } | |
40 | ||
41 | act.sa_handler = handler; | |
a992f506 ZW |
42 | __sigemptyset (&act.sa_mask); |
43 | __sigaddset (&act.sa_mask, sig); | |
df4ef2ab | 44 | act.sa_flags = __sigismember (&_sigintr, sig) ? 0 : SA_RESTART; |
28f540f4 RM |
45 | if (__sigaction (sig, &act, &oact) < 0) |
46 | return SIG_ERR; | |
47 | ||
48 | return oact.sa_handler; | |
49 | } | |
df4ef2ab UD |
50 | weak_alias (__bsd_signal, bsd_signal) |
51 | weak_alias (__bsd_signal, signal) | |
52 | weak_alias (__bsd_signal, ssignal) |