xref: /titanic_41/usr/src/lib/libast/common/misc/signal.c (revision eb82ff87b34e625264561b2d267577cf9821dab0)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2009 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 
24 /*
25  * signal that disables syscall restart on interrupt with clear signal mask
26  * fun==SIG_DFL also unblocks signal
27  */
28 
29 #if !_UWIN
30 
31 #undef	signal
32 #define signal		______signal
33 
34 #endif
35 
36 #include <ast.h>
37 #include <sig.h>
38 
39 #if !_UWIN
40 
41 #undef	signal
42 
43 #undef	_def_map_ast
44 #include <ast_map.h>
45 
46 #if defined(__EXPORT__)
47 #define extern	__EXPORT__
48 #endif
49 
50 #endif
51 
52 #if defined(SV_ABORT)
53 #undef	SV_INTERRUPT
54 #define SV_INTERRUPT	SV_ABORT
55 #endif
56 
57 #if !_std_signal && (_lib_sigaction && defined(SA_NOCLDSTOP) || _lib_sigvec && defined(SV_INTERRUPT))
58 
59 #if !defined(SA_NOCLDSTOP) || !defined(SA_INTERRUPT) && defined(SV_INTERRUPT)
60 #undef	SA_INTERRUPT
61 #define SA_INTERRUPT	SV_INTERRUPT
62 #undef	sigaction
63 #define sigaction	sigvec
64 #undef	sigemptyset
65 #define sigemptyset(p)	(*(p)=0)
66 #undef	sa_flags
67 #define sa_flags	sv_flags
68 #undef	sa_handler
69 #define sa_handler	sv_handler
70 #undef	sa_mask
71 #define	sa_mask		sv_mask
72 #endif
73 
74 extern Sig_handler_t
75 signal(int sig, Sig_handler_t fun)
76 {
77 	struct sigaction	na;
78 	struct sigaction	oa;
79 	int			unblock;
80 #ifdef SIGNO_MASK
81 	unsigned int		flags;
82 #endif
83 
84 	if (sig < 0)
85 	{
86 		sig = -sig;
87 		unblock = 0;
88 	}
89 	else
90 		unblock = fun == SIG_DFL;
91 #ifdef SIGNO_MASK
92 	flags = sig & ~SIGNO_MASK;
93 	sig &= SIGNO_MASK;
94 #endif
95 	memzero(&na, sizeof(na));
96 	na.sa_handler = fun;
97 #if defined(SA_INTERRUPT) || defined(SA_RESTART)
98 	switch (sig)
99 	{
100 #if defined(SIGIO) || defined(SIGTSTP) || defined(SIGTTIN) || defined(SIGTTOU)
101 #if defined(SIGIO)
102 	case SIGIO:
103 #endif
104 #if defined(SIGTSTP)
105 	case SIGTSTP:
106 #endif
107 #if defined(SIGTTIN)
108 	case SIGTTIN:
109 #endif
110 #if defined(SIGTTOU)
111 	case SIGTTOU:
112 #endif
113 #if defined(SA_RESTART)
114 		na.sa_flags = SA_RESTART;
115 #endif
116 		break;
117 #endif
118 	default:
119 #if defined(SA_INTERRUPT)
120 		na.sa_flags = SA_INTERRUPT;
121 #endif
122 		break;
123 	}
124 #endif
125 	if (sigaction(sig, &na, &oa))
126 		return 0;
127 	if (unblock)
128 		sigunblock(sig);
129 	return oa.sa_handler;
130 }
131 
132 #else
133 
134 NoN(signal)
135 
136 #endif
137