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