/*
* Copyright (c) 2000-2001 Proofpoint, Inc. and its suppliers.
* All rights reserved.
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the sendmail distribution.
*/
#endif /* SM_CONF_SETITIMER */
#include <errno.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <signal.h>
/*
** SM_SIGNAL -- set a signal handler
**
** This is essentially old BSD "signal(3)".
**
** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
** DOING.
*/
int sig;
{
struct sigaction n, o;
# endif /* defined(SA_RESTART) || (!defined(SYS5SIGNALS) && !defined(BSD4_3)) */
/*
** First, try for modern signal calls
** and restartable syscalls
*/
# ifdef SA_RESTART
(void) memset(&n, '\0', sizeof n);
# if USE_SA_SIGACTION
# else /* USE_SA_SIGACTION */
n.sa_handler = handler;
n.sa_flags = SA_RESTART;
# endif /* USE_SA_SIGACTION */
return SIG_ERR;
return o.sa_handler;
# else /* SA_RESTART */
/*
** Else check for SYS5SIGNALS or
** BSD4_3 signals
*/
# if defined(SYS5SIGNALS) || defined(BSD4_3)
# ifdef BSD4_3
# else /* BSD4_3 */
# endif /* BSD4_3 */
# else /* defined(SYS5SIGNALS) || defined(BSD4_3) */
/*
** Finally, if nothing else is available,
** go for a default
*/
(void) memset(&n, '\0', sizeof n);
n.sa_handler = handler;
return SIG_ERR;
return o.sa_handler;
# endif /* defined(SYS5SIGNALS) || defined(BSD4_3) */
# endif /* SA_RESTART */
}
/*
** SM_BLOCKSIGNAL -- hold a signal to prevent delivery
**
** Parameters:
** sig -- the signal to block.
**
** Returns:
** 1 signal was previously blocked
** 0 signal was not previously blocked
** -1 on failure.
*/
int
int sig;
{
# ifdef BSD4_3
# ifndef sigmask
# endif /* ! sigmask */
# else /* BSD4_3 */
# ifdef ALTOS_SYSTEM_V
return -1;
else
# else /* ALTOS_SYSTEM_V */
(void) sigemptyset(&sset);
return -1;
else
# endif /* ALTOS_SYSTEM_V */
# endif /* BSD4_3 */
}
/*
** SM_RELEASESIGNAL -- release a held signal
**
** Parameters:
** sig -- the signal to release.
**
** Returns:
** 1 signal was previously blocked
** 0 signal was not previously blocked
** -1 on failure.
*/
int
int sig;
{
# ifdef BSD4_3
# else /* BSD4_3 */
# ifdef ALTOS_SYSTEM_V
return -1;
else
# else /* ALTOS_SYSTEM_V */
(void) sigemptyset(&sset);
return -1;
else
# endif /* ALTOS_SYSTEM_V */
# endif /* BSD4_3 */
}
/*
** PEND_SIGNAL -- Add a signal to the pending signal list
**
** Parameters:
** sig -- signal to add
**
** Returns:
** none.
**
** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
** DOING.
*/
void
int sig;
{
int sigbit;
#endif /* SM_CONF_SETITIMER */
/*
** Don't want to interrupt something critical, hence delay
** the alarm for one second. Hopefully, by then we
** will be out of the critical section. If not, then
** we will just delay again. The events to be run will
** still all be run, maybe just a little bit late.
*/
switch (sig)
{
case SIGHUP:
break;
case SIGINT:
break;
case SIGTERM:
break;
case SIGUSR1:
break;
case SIGALRM:
/* don't have to pend these */
sigbit = 0;
break;
default:
/* If we get here, we are in trouble */
abort();
/* NOTREACHED */
/* shut up stupid compiler warning on HP-UX 11 */
sigbit = 0;
break;
}
if (sigbit != 0)
PendingSignal |= sigbit;
#else /* SM_CONF_SETITIMER */
(void) alarm(1);
#endif /* SM_CONF_SETITIMER */
errno = save_errno;
}
/*
** SM_ALLSIGNALS -- act on all signals
**
** Parameters:
** block -- whether to block or release all signals.
**
** Returns:
** none.
*/
void
bool block;
{
# ifdef BSD4_3
# ifndef sigmask
# endif /* ! sigmask */
if (block)
{
int mask = 0;
}
else
sigsetmask(0);
# else /* BSD4_3 */
# ifdef ALTOS_SYSTEM_V
if (block)
{
}
else
{
}
# else /* ALTOS_SYSTEM_V */
(void) sigemptyset(&sset);
# endif /* ALTOS_SYSTEM_V */
# endif /* BSD4_3 */
}
/*
** SM_SIGNAL_NOOP -- A signal no-op function
**
** Parameters:
** sig -- signal received
**
** Returns:
** SIGFUNC_RETURN
*/
/* ARGSUSED */
int sig;
{
errno = save_errno;
return SIGFUNC_RETURN;
}