Date: Thu, 30 Oct 2003 01:25:41 +0300 (MSK) From: sp@alkor.ru To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/58696: /sbin/natd feature request & possible patch Message-ID: <200310292225.h9TMPf1K008990@rvrng.alkor.ru> Resent-Message-ID: <200310292040.h9TKeAOW071529@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 58696 >Category: bin >Synopsis: /sbin/natd feature request & possible patch >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Wed Oct 29 12:40:10 PST 2003 >Closed-Date: >Last-Modified: >Originator: >Release: FreeBSD 4.9-STABLE i386 >Organization: >Environment: System: FreeBSD rvrng.alkor.ru 4.9-STABLE FreeBSD 4.9-STABLE #1: Mon Oct 27 16:39:26 MSK 2003 root@:/usr/obj/usr/src/sys/RVRNG i386 >Description: Add possibility to alter pidfile location and shutdown timeout >How-To-Repeat: When running multiple nat daemons all they are writing pid file in the same place. After receiving termination signal (SIGTERM or like) natd always sleeps 10 seconds before exit. It's not convenient in some environments. The patch attached adds to options -- one to set alternate pid file, and other sets shutdown timeout in milliseconds. >Fix: --- natd.c.orig Thu Oct 30 00:56:31 2003 +++ natd.c Thu Oct 30 01:07:43 2003 @@ -44,6 +44,8 @@ #include <syslog.h> #include <unistd.h> +#include <sys/param.h> + #include "natd.h" /* @@ -123,6 +125,9 @@ static int logFacility; static int logIpfwDenied; +static int exitTimeout; +static char pidPath[MAXPATHLEN]; + int main (int argc, char** argv) { int divertIn; @@ -156,6 +161,8 @@ logDropped = 0; logFacility = LOG_DAEMON; logIpfwDenied = -1; + strcpy(pidPath, PIDFILE); + exitTimeout = EXIT_TIMEOUT; ParseArgs (argc, argv); /* @@ -380,7 +387,7 @@ } if (background) - unlink (PIDFILE); + unlink (pidPath); return 0; } @@ -392,7 +399,7 @@ daemon (0, 0); background = 1; - pidFile = fopen (PIDFILE, "w"); + pidFile = fopen (pidPath, "w"); if (pidFile) { fprintf (pidFile, "%d\n", getpid ()); @@ -805,7 +812,10 @@ */ siginterrupt(SIGALRM, 1); signal (SIGALRM, Shutdown); - alarm (10); + if(exitTimeout) + ualarm(1000*exitTimeout, 100); + else + ualarm(100, 100); } static void Shutdown (int sig) @@ -836,7 +846,9 @@ LogDenied, LogFacility, PunchFW, - LogIpfwDenied + LogIpfwDenied, + pidPathOption, + exitTimeoutOption }; enum Param { @@ -1063,6 +1075,21 @@ "log packets converted by natd, but denied by ipfw", "log_ipfw_denied", NULL }, + { pidPathOption, + 0, + String, + "file_path", + "store pid in specified file", + "pid_path", + "P" }, + { exitTimeoutOption, + 0, + Numeric, + "milliseconds", + "timeout before exiting on signal in milliseconds", + "exit_timeout", + "X" }, + }; static void ParseOption (const char* option, const char* parms) @@ -1249,6 +1276,19 @@ case LogIpfwDenied: logIpfwDenied = yesNoValue;; + break; + + case exitTimeoutOption: + if((exitTimeout = uNumValue) > MAX_EXIT_TIMEOUT) + err(1, "Exit timeout too large"); + break; + + case pidPathOption: + /* Need checking ? */ + if(!*strValue) + errx(1, "Empty pid path"); + if(realpath(strValue, pidPath) == 0) + err(1, "Invalid pid path"); break; } } --- natd.h.orig Thu Oct 30 00:56:37 2003 +++ natd.h Thu Oct 30 00:59:41 2003 @@ -13,6 +13,10 @@ */ #define PIDFILE "/var/run/natd.pid" + +#define EXIT_TIMEOUT 10000 +#define MAX_EXIT_TIMEOUT 99999 + #define INPUT 1 #define OUTPUT 2 #define DONT_KNOW 3 >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200310292225.h9TMPf1K008990>