xref: /titanic_41/usr/src/lib/libast/common/misc/signal.c (revision 54925bf60766fbb4f1f2d7c843721406a7b7a3fb)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *           Copyright (c) 1985-2007 AT&T Knowledge Ventures            *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                      by AT&T Knowledge Ventures                      *
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 #ifdef SIGNO_MASK
80 	unsigned int		flags;
81 #endif
82 
83 #ifdef SIGNO_MASK
84 	flags = sig & ~SIGNO_MASK;
85 	sig &= SIGNO_MASK;
86 #endif
87 	if (fun == SIG_DFL)
88 		sigunblock(sig);
89 	memzero(&na, sizeof(na));
90 	na.sa_handler = fun;
91 #if defined(SA_INTERRUPT) || defined(SA_RESTART)
92 	switch (sig)
93 	{
94 #if defined(SIGIO) || defined(SIGTSTP) || defined(SIGTTIN) || defined(SIGTTOU)
95 #if defined(SIGIO)
96 	case SIGIO:
97 #endif
98 #if defined(SIGTSTP)
99 	case SIGTSTP:
100 #endif
101 #if defined(SIGTTIN)
102 	case SIGTTIN:
103 #endif
104 #if defined(SIGTTOU)
105 	case SIGTTOU:
106 #endif
107 #if defined(SA_RESTART)
108 		na.sa_flags = SA_RESTART;
109 #endif
110 		break;
111 #endif
112 	default:
113 #if defined(SA_INTERRUPT)
114 		na.sa_flags = SA_INTERRUPT;
115 #endif
116 		break;
117 	}
118 #endif
119 	return(sigaction(sig, &na, &oa) ? (Sig_handler_t)0 : oa.sa_handler);
120 }
121 
122 #else
123 
124 NoN(signal)
125 
126 #endif
127