Add exit_delay parameter to control daemon exit delay after signal.

PR:		bin/58696
Submitted by:	sp@alkor.ru
This commit is contained in:
mav 2008-06-22 22:14:02 +00:00
parent 1e17e3cd45
commit 2ee7f37628
3 changed files with 31 additions and 4 deletions

View File

@ -1,5 +1,5 @@
.\" $FreeBSD$
.Dd February 4, 2008
.Dd June 23, 2008
.Dt NATD 8
.Os
.Sh NAME
@ -36,6 +36,7 @@
.Op Fl skinny_port Ar port
.Op Fl log_ipfw_denied
.Op Fl pid_file | P Ar pidfile
.Op Fl exit_delay | P Ar ms
.Ek
.Sh DESCRIPTION
The
@ -557,6 +558,10 @@ This is the default with
Specify an alternate file in which to store the process ID.
The default is
.Pa /var/run/natd.pid .
.It Fl exit_delay Ar ms
Specify delay in ms before daemon exit after signal.
The default is
.Pa 10000 .
.El
.Sh RUNNING NATD
The following steps are necessary before attempting to run

View File

@ -147,6 +147,8 @@ static const char* pidName;
static int routeSock;
static int globalPort;
static int divertGlobal;
static int exitDelay;
int main (int argc, char** argv)
{
@ -174,6 +176,7 @@ int main (int argc, char** argv)
icmpSock = -1;
fdMax = -1;
divertGlobal = -1;
exitDelay = EXIT_DELAY;
ParseArgs (argc, argv);
/*
@ -347,7 +350,10 @@ int main (int argc, char** argv)
*/
siginterrupt(SIGTERM, 1);
siginterrupt(SIGHUP, 1);
signal (SIGTERM, InitiateShutdown);
if (exitDelay)
signal(SIGTERM, InitiateShutdown);
else
signal(SIGTERM, Shutdown);
signal (SIGHUP, RefreshAddr);
/*
* Set alias address if it has been given.
@ -984,7 +990,7 @@ static void InitiateShutdown (int sig __unused)
*/
siginterrupt(SIGALRM, 1);
signal (SIGALRM, Shutdown);
alarm (10);
ualarm(exitDelay*1000, 1000);
}
static void Shutdown (int sig __unused)
@ -1019,7 +1025,8 @@ enum Option {
PunchFW,
SkinnyPort,
LogIpfwDenied,
PidFile
PidFile,
ExitDelay
};
enum Param {
@ -1277,6 +1284,13 @@ static struct OptionInfo optionTable[] = {
"name of aliasing engine instance",
"instance",
NULL },
{ ExitDelay,
0,
Numeric,
"ms",
"delay in ms before daemon exit after signal",
"exit_delay",
NULL },
};
static void ParseOption (const char* option, const char* parms)
@ -1479,6 +1493,11 @@ static void ParseOption (const char* option, const char* parms)
case Instance:
NewInstance(strValue);
break;
case ExitDelay:
if (numValue < 0 || numValue > MAX_EXIT_DELAY)
errx(1, "Incorrect exit delay: %d", numValue);
exitDelay = numValue;
break;
}
}

View File

@ -17,6 +17,9 @@
#define OUTPUT 2
#define DONT_KNOW 3
#define EXIT_DELAY 10000
#define MAX_EXIT_DELAY 999999
extern void Quit (const char* msg);
extern void Warn (const char* msg);
extern int SendNeedFragIcmp (int sock, struct ip* failedDgram, int mtu);