]> git.saurik.com Git - apple/libc.git/blob - sys.subproj/sigaction.c
Libc-167.tar.gz
[apple/libc.git] / sys.subproj / sigaction.c
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
24 *
25 * @(#)sigaction.c 1.0
26 */
27
28 #include <sys/syscall.h>
29 #include <signal.h>
30 #include <sys/signal.h>
31 #include <errno.h>
32
33 /*
34 * Intercept the sigaction syscall and use our signal trampoline
35 * as the signal handler instead. The code here is derived
36 * from sigvec in sys/kern_sig.c.
37 */
38
39 extern void (*sigcatch[NSIG])();
40 #if defined(__DYNAMIC__)
41 extern int __in_sigtramp;
42 #endif
43
44 static int
45 sigaction__ (sig, nsv, osv, bind)
46 int sig;
47 register struct sigaction *nsv, *osv;
48 int bind;
49 {
50 struct sigaction vec;
51 void (*prevsig)();
52 extern void _sigtramp();
53
54 if (sig <= 0 || sig >= NSIG || sig == SIGKILL || sig == SIGSTOP) {
55 errno = EINVAL;
56 return (-1);
57 }
58 prevsig = sigcatch[sig];
59 if (nsv) {
60 sigcatch[sig] = nsv->sa_handler;
61 vec = *nsv; nsv = &vec;
62 if (nsv->sa_handler != (void (*)())SIG_DFL && nsv->sa_handler != (void (*)())SIG_IGN) {
63 nsv->sa_handler = _sigtramp;
64 #ifdef __DYNAMIC__
65 if (bind && (__in_sigtramp == 0)) // XXX
66 _dyld_bind_fully_image_containing_address(sigcatch[sig]);
67 #endif
68 }
69 }
70 if (syscall (SYS_sigaction, sig, nsv, osv) < 0) {
71 sigcatch[sig] = prevsig;
72 return (-1);
73 }
74 if (osv && prevsig)
75 osv->sa_handler = prevsig;
76 return (0);
77 }
78
79
80 int
81 sigaction (sig, nsv, osv)
82 int sig;
83 register const struct sigaction *nsv;
84 register struct sigaction *osv;
85 {
86 return sigaction__(sig, nsv, osv, 1);
87 }
88
89 // XXX
90 #ifdef __DYNAMIC__
91
92 int
93 _sigaction_nobind (sig, nsv, osv)
94 int sig;
95 register const struct sigaction *nsv;
96 register struct sigaction *osv;
97 {
98 return sigaction__(sig, nsv, osv, 0);
99 }
100 #endif
101