xref: /titanic_50/usr/src/cmd/sendmail/include/sm/signal.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.
3*7c478bd9Sstevel@tonic-gate  *	All rights reserved.
4*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
5*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1988, 1993
6*7c478bd9Sstevel@tonic-gate  *	The Regents of the University of California.  All rights reserved.
7*7c478bd9Sstevel@tonic-gate  *
8*7c478bd9Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
9*7c478bd9Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
10*7c478bd9Sstevel@tonic-gate  * the sendmail distribution.
11*7c478bd9Sstevel@tonic-gate  *
12*7c478bd9Sstevel@tonic-gate  *	$Id: signal.h,v 1.16 2001/07/20 19:48:21 gshapiro Exp $
13*7c478bd9Sstevel@tonic-gate  */
14*7c478bd9Sstevel@tonic-gate 
15*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
16*7c478bd9Sstevel@tonic-gate 
17*7c478bd9Sstevel@tonic-gate /*
18*7c478bd9Sstevel@tonic-gate **  SIGNAL.H -- libsm (and sendmail) signal facilities
19*7c478bd9Sstevel@tonic-gate **		Extracted from sendmail/conf.h and focusing
20*7c478bd9Sstevel@tonic-gate **		on signal configuration.
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate 
23*7c478bd9Sstevel@tonic-gate #ifndef SM_SIGNAL_H
24*7c478bd9Sstevel@tonic-gate #define SM_SIGNAL_H 1
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
27*7c478bd9Sstevel@tonic-gate #include <limits.h>
28*7c478bd9Sstevel@tonic-gate #include <signal.h>
29*7c478bd9Sstevel@tonic-gate #include <sm/cdefs.h>
30*7c478bd9Sstevel@tonic-gate #include <sm/conf.h>
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate /*
33*7c478bd9Sstevel@tonic-gate **  Critical signal sections
34*7c478bd9Sstevel@tonic-gate */
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #define PEND_SIGHUP	0x0001
37*7c478bd9Sstevel@tonic-gate #define PEND_SIGINT	0x0002
38*7c478bd9Sstevel@tonic-gate #define PEND_SIGTERM	0x0004
39*7c478bd9Sstevel@tonic-gate #define PEND_SIGUSR1	0x0008
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate #define ENTER_CRITICAL()	InCriticalSection++
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #define LEAVE_CRITICAL()						\
44*7c478bd9Sstevel@tonic-gate do									\
45*7c478bd9Sstevel@tonic-gate {									\
46*7c478bd9Sstevel@tonic-gate 	if (InCriticalSection > 0)					\
47*7c478bd9Sstevel@tonic-gate 		InCriticalSection--;					\
48*7c478bd9Sstevel@tonic-gate } while (0)
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate #define CHECK_CRITICAL(sig)						\
51*7c478bd9Sstevel@tonic-gate do									\
52*7c478bd9Sstevel@tonic-gate {									\
53*7c478bd9Sstevel@tonic-gate 	if (InCriticalSection > 0 && (sig) != 0)			\
54*7c478bd9Sstevel@tonic-gate 	{								\
55*7c478bd9Sstevel@tonic-gate 		pend_signal((sig));					\
56*7c478bd9Sstevel@tonic-gate 		return SIGFUNC_RETURN;					\
57*7c478bd9Sstevel@tonic-gate 	}								\
58*7c478bd9Sstevel@tonic-gate } while (0)
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate /* variables */
61*7c478bd9Sstevel@tonic-gate extern unsigned int	volatile InCriticalSection;	/* >0 if in critical section */
62*7c478bd9Sstevel@tonic-gate extern int		volatile PendingSignal;	/* pending signal to resend */
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate /* functions */
65*7c478bd9Sstevel@tonic-gate extern void		pend_signal __P((int));
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate /* reset signal in case System V semantics */
68*7c478bd9Sstevel@tonic-gate #ifdef SYS5SIGNALS
69*7c478bd9Sstevel@tonic-gate # define FIX_SYSV_SIGNAL(sig, handler)					\
70*7c478bd9Sstevel@tonic-gate {									\
71*7c478bd9Sstevel@tonic-gate 	if ((sig) != 0)							\
72*7c478bd9Sstevel@tonic-gate 		(void) sm_signal((sig), (handler));			\
73*7c478bd9Sstevel@tonic-gate }
74*7c478bd9Sstevel@tonic-gate #else /* SYS5SIGNALS */
75*7c478bd9Sstevel@tonic-gate # define FIX_SYSV_SIGNAL(sig, handler)	{ /* EMPTY */ }
76*7c478bd9Sstevel@tonic-gate #endif /* SYS5SIGNALS */
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate extern void		sm_allsignals __P((bool));
79*7c478bd9Sstevel@tonic-gate extern int		sm_blocksignal __P((int));
80*7c478bd9Sstevel@tonic-gate extern int		sm_releasesignal __P((int));
81*7c478bd9Sstevel@tonic-gate extern sigfunc_t	sm_signal __P((int, sigfunc_t));
82*7c478bd9Sstevel@tonic-gate extern SIGFUNC_DECL	sm_signal_noop __P((int));
83*7c478bd9Sstevel@tonic-gate #endif /* SM_SIGNAL_H */
84