OSDN Git Service

Replace FSF snail mail address with URLs
[uclinux-h8/uClibc.git] / libc / signal / sigset.c
1 /* Copyright (C) 1998, 2000, 2005 Free Software Foundation, Inc.
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
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.
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
12    Lesser General Public License for more details.
13
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/>.  */
17
18 #include <errno.h>
19 #define __need_NULL
20 #include <stddef.h>
21 #include <signal.h>
22 #include <string.h>
23
24 /* Set the disposition for SIG.  */
25 __sighandler_t sigset (int sig, __sighandler_t disp)
26 {
27   struct sigaction act, oact;
28   sigset_t set;
29
30   /* Check signal extents to protect __sigismember.  */
31   if (disp == SIG_ERR || sig < 1 || sig >= NSIG)
32     {
33       __set_errno (EINVAL);
34       return SIG_ERR;
35     }
36
37 #ifdef SIG_HOLD
38   /* Handle SIG_HOLD first.  */
39   if (disp == SIG_HOLD)
40     {
41       __sigemptyset (&set);
42       __sigaddset (&set, sig);
43
44       /* Add the signal set to the current signal mask.  */
45       sigprocmask (SIG_BLOCK, &set, NULL); /* can't fail */
46
47       return SIG_HOLD;
48     }
49 #endif  /* SIG_HOLD */
50
51   memset(&act, 0, sizeof(act));
52   act.sa_handler = disp;
53   /* In Linux (as of 2.6.25), fails only if sig is SIGKILL or SIGSTOP */
54   if (sigaction (sig, &act, &oact) < 0)
55     return SIG_ERR;
56
57   /* Create an empty signal set. Add the specified signal.  */
58   __sigemptyset (&set);
59   __sigaddset (&set, sig);
60
61   /* Remove the signal set from the current signal mask.  */
62   sigprocmask (SIG_UNBLOCK, &set, NULL); /* can't fail */
63
64   return oact.sa_handler;
65 }