190792Sgshapiro/*
2261370Sgshapiro * Copyright (c) 1998-2001 Proofpoint, Inc. and its suppliers.
390792Sgshapiro *	All rights reserved.
490792Sgshapiro * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
590792Sgshapiro * Copyright (c) 1988, 1993
690792Sgshapiro *	The Regents of the University of California.  All rights reserved.
790792Sgshapiro *
890792Sgshapiro * By using this file, you agree to the terms and conditions set
990792Sgshapiro * forth in the LICENSE file which can be found at the top level of
1090792Sgshapiro * the sendmail distribution.
1190792Sgshapiro *
12266711Sgshapiro *	$Id: signal.h,v 1.17 2013-11-22 20:51:31 ca Exp $
1390792Sgshapiro */
1490792Sgshapiro
1590792Sgshapiro/*
1690792Sgshapiro**  SIGNAL.H -- libsm (and sendmail) signal facilities
1790792Sgshapiro**		Extracted from sendmail/conf.h and focusing
1890792Sgshapiro**		on signal configuration.
1990792Sgshapiro*/
2090792Sgshapiro
2190792Sgshapiro#ifndef SM_SIGNAL_H
2290792Sgshapiro#define SM_SIGNAL_H 1
2390792Sgshapiro
2490792Sgshapiro#include <sys/types.h>
2590792Sgshapiro#include <limits.h>
2690792Sgshapiro#include <signal.h>
2790792Sgshapiro#include <sm/cdefs.h>
2890792Sgshapiro#include <sm/conf.h>
2990792Sgshapiro
3090792Sgshapiro/*
3190792Sgshapiro**  Critical signal sections
3290792Sgshapiro*/
3390792Sgshapiro
3490792Sgshapiro#define PEND_SIGHUP	0x0001
3590792Sgshapiro#define PEND_SIGINT	0x0002
3690792Sgshapiro#define PEND_SIGTERM	0x0004
3790792Sgshapiro#define PEND_SIGUSR1	0x0008
3890792Sgshapiro
3990792Sgshapiro#define ENTER_CRITICAL()	InCriticalSection++
4090792Sgshapiro
4190792Sgshapiro#define LEAVE_CRITICAL()						\
4290792Sgshapirodo									\
4390792Sgshapiro{									\
4490792Sgshapiro	if (InCriticalSection > 0)					\
4590792Sgshapiro		InCriticalSection--;					\
4690792Sgshapiro} while (0)
4790792Sgshapiro
4890792Sgshapiro#define CHECK_CRITICAL(sig)						\
4990792Sgshapirodo									\
5090792Sgshapiro{									\
5190792Sgshapiro	if (InCriticalSection > 0 && (sig) != 0)			\
5290792Sgshapiro	{								\
5390792Sgshapiro		pend_signal((sig));					\
5490792Sgshapiro		return SIGFUNC_RETURN;					\
5590792Sgshapiro	}								\
5690792Sgshapiro} while (0)
5790792Sgshapiro
5890792Sgshapiro/* variables */
5990792Sgshapiroextern unsigned int	volatile InCriticalSection;	/* >0 if in critical section */
6090792Sgshapiroextern int		volatile PendingSignal;	/* pending signal to resend */
6190792Sgshapiro
6290792Sgshapiro/* functions */
6390792Sgshapiroextern void		pend_signal __P((int));
6490792Sgshapiro
6590792Sgshapiro/* reset signal in case System V semantics */
6690792Sgshapiro#ifdef SYS5SIGNALS
6790792Sgshapiro# define FIX_SYSV_SIGNAL(sig, handler)					\
6890792Sgshapiro{									\
6990792Sgshapiro	if ((sig) != 0)							\
7090792Sgshapiro		(void) sm_signal((sig), (handler));			\
7190792Sgshapiro}
7290792Sgshapiro#else /* SYS5SIGNALS */
7390792Sgshapiro# define FIX_SYSV_SIGNAL(sig, handler)	{ /* EMPTY */ }
7490792Sgshapiro#endif /* SYS5SIGNALS */
7590792Sgshapiro
7690792Sgshapiroextern void		sm_allsignals __P((bool));
7790792Sgshapiroextern int		sm_blocksignal __P((int));
7890792Sgshapiroextern int		sm_releasesignal __P((int));
7990792Sgshapiroextern sigfunc_t	sm_signal __P((int, sigfunc_t));
8090792Sgshapiroextern SIGFUNC_DECL	sm_signal_noop __P((int));
8190792Sgshapiro#endif /* SM_SIGNAL_H */
82