/*
* Copyright (c) 1999-2004, 2006 Sendmail, 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.
*
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "libmilter.h"
/*
** thread to handle signals
*/
static void *mi_signal_thread __P((void *));
static int mi_spawn_signal_thread __P((char *));
/*
** MI_STOP -- return value of MilterStop
**
** Parameters:
** none.
**
** Returns:
** value of MilterStop
*/
int
mi_stop()
{
return MilterStop;
}
/*
** MI_STOP_MILTERS -- set value of MilterStop
**
** Parameters:
** v -- new value for MilterStop.
**
** Returns:
** none.
*/
void
int v;
{
(void) smutex_lock(&M_Mutex);
if (MilterStop < v)
MilterStop = v;
/* close listen socket */
mi_closener();
(void) smutex_unlock(&M_Mutex);
}
/*
** MI_CLEAN_SIGNALS -- clean up signal handler thread
**
** Parameters:
** none.
**
** Returns:
** none.
*/
void
{
(void) smutex_destroy(&M_Mutex);
}
/*
** MI_SIGNAL_THREAD -- thread to deal with signals
**
** Parameters:
** name -- name of milter
**
** Returns:
** NULL
*/
static void *
void *name;
{
(void) sigemptyset(&set);
/* Handle Ctrl-C gracefully for debugging */
errs = 0;
for (;;)
{
#else /* defined(SOLARIS) || defined(__svr5__) */
#endif /* defined(SOLARIS) || defined(__svr5__) */
{
/* some OS return -1 and set errno: copy it */
if (sigerr <= 0)
/* this can happen on OSF/1 (at least) */
continue;
"%s: sigwait returned error: %d",
if (++errs > MAX_FAILS_T)
{
return NULL;
}
continue;
}
errs = 0;
switch (sig)
{
case SIGHUP:
case SIGTERM:
return NULL;
case SIGINT:
return NULL;
default:
"%s: sigwait returned unmasked signal: %d",
break;
}
}
/* NOTREACHED */
}
/*
** MI_SPAWN_SIGNAL_THREAD -- spawn thread to handle signals
**
** Parameters:
** name -- name of milter
**
** Returns:
*/
static int
char *name;
{
int r;
/* Mask HUP and KILL signals */
(void) sigemptyset(&set);
{
"%s: Couldn't mask HUP and KILL signals", name);
return MI_FAILURE;
}
if (r != 0)
{
"%s: Couldn't start signal thread: %d",
name, r);
return MI_FAILURE;
}
return MI_SUCCESS;
}
/*
** MI_CONTROL_STARTUP -- startup for thread to handle signals
**
** Parameters:
** name -- name of milter
**
** Returns:
*/
int
char *name;
{
if (!smutex_init(&M_Mutex))
{
"%s: Couldn't initialize control pipe mutex", name);
return MI_FAILURE;
}
/*
** spawn_signal_thread must happen before other threads are spawned
** off so that it can mask the right signals and other threads
** will inherit that mask.
*/
{
"%s: Couldn't spawn signal thread", name);
(void) smutex_destroy(&M_Mutex);
return MI_FAILURE;
}
return MI_SUCCESS;
}