diff options
author | mav <mav@FreeBSD.org> | 2008-06-22 22:14:02 +0000 |
---|---|---|
committer | mav <mav@FreeBSD.org> | 2008-06-22 22:14:02 +0000 |
commit | 2ee7f37628c9a058ef5d75c44957a23f0a56d857 (patch) | |
tree | 0a8eed37e1bfcbc8f6c9b9c9b30f18aca0733794 | |
parent | 1e17e3cd45bf4ec8798dbb1b2f8b9d03917ac322 (diff) | |
download | FreeBSD-src-2ee7f37628c9a058ef5d75c44957a23f0a56d857.zip FreeBSD-src-2ee7f37628c9a058ef5d75c44957a23f0a56d857.tar.gz |
Add exit_delay parameter to control daemon exit delay after signal.
PR: bin/58696
Submitted by: sp@alkor.ru
-rw-r--r-- | sbin/natd/natd.8 | 7 | ||||
-rw-r--r-- | sbin/natd/natd.c | 25 | ||||
-rw-r--r-- | sbin/natd/natd.h | 3 |
3 files changed, 31 insertions, 4 deletions
diff --git a/sbin/natd/natd.8 b/sbin/natd/natd.8 index e0b526c..6bed424 100644 --- a/sbin/natd/natd.8 +++ b/sbin/natd/natd.8 @@ -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 diff --git a/sbin/natd/natd.c b/sbin/natd/natd.c index 64d612e..3a5a644 100644 --- a/sbin/natd/natd.c +++ b/sbin/natd/natd.c @@ -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; } } diff --git a/sbin/natd/natd.h b/sbin/natd/natd.h index a05d1f7..32bffd8 100644 --- a/sbin/natd/natd.h +++ b/sbin/natd/natd.h @@ -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); |