misc/153362: patch to add -p flag to set pidfile for rtadvd

Joe Holden joe at rewt.org.uk
Wed Dec 22 02:00:24 UTC 2010


>Number:         153362
>Category:       misc
>Synopsis:       patch to add -p flag to set pidfile for rtadvd
>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 Dec 22 02:00:23 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     Joe Holden
>Release:        8.2-PRERELEASE
>Organization:
Pseudo Networks Limited
>Environment:
>Description:
I have attached a quick/dirty patch to add a -p flag that sets an alternative pidfile location as well as unlinking pidfile before exit... my programming skills are pretty much 0, so it will probably need to be rewritten.
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

diff -u -r rtadvd.orig/rtadvd.8 rtadvd/rtadvd.8
--- rtadvd.orig/rtadvd.8	2010-12-22 01:32:38.000000000 +0000
+++ rtadvd/rtadvd.8	2010-12-22 01:22:15.000000000 +0000
@@ -144,6 +144,8 @@
 .It Fl s
 Do not add or delete prefixes dynamically.
 Only statically configured prefixes, if any, will be advertised.
+.It Fl p
+Set an alternate pidfile location.
 .El
 .Pp
 Upon receipt of signal
diff -u -r rtadvd.orig/rtadvd.c rtadvd/rtadvd.c
--- rtadvd.orig/rtadvd.c	2010-12-22 01:32:38.000000000 +0000
+++ rtadvd/rtadvd.c	2010-12-22 01:16:54.000000000 +0000
@@ -81,6 +81,7 @@
 struct in6_addr in6a_site_allrouters;
 static char *dumpfilename = "/var/run/rtadvd.dump"; /* XXX: should be configurable */
 static char *pidfilename = "/var/run/rtadvd.pid"; /* should be configurable */
+char *pidfilecust;
 static char *mcastif;
 int sock;
 int rtsock = -1;
@@ -163,7 +164,7 @@
 	pid_t pid;
 
 	/* get command line options and arguments */
-	while ((ch = getopt(argc, argv, "c:dDfM:Rs")) != -1) {
+	while ((ch = getopt(argc, argv, "c:dDfMp:Rs")) != -1) {
 		switch (ch) {
 		case 'c':
 			conffile = optarg;
@@ -189,13 +190,16 @@
 		case 's':
 			sflag = 1;
 			break;
+		case 'p':
+			pidfilecust = optarg;
+			break;
 		}
 	}
 	argc -= optind;
 	argv += optind;
 	if (argc == 0) {
 		fprintf(stderr,
-			"usage: rtadvd [-dDfMRs] [-c conffile] "
+			"usage: rtadvd [-dDfMRsp] [-c conffile] "
 			"interfaces...\n");
 		exit(1);
 	}
@@ -241,13 +245,24 @@
 
 	/* record the current PID */
 	pid = getpid();
-	if ((pidfp = fopen(pidfilename, "w")) == NULL) {
-		syslog(LOG_ERR,
-		    "<%s> failed to open the pid log file, run anyway.",
-		    __func__);
-	} else {
-		fprintf(pidfp, "%d\n", pid);
-		fclose(pidfp);
+	if (!pidfilecust) {
+		if ((pidfp = fopen(pidfilename, "w")) == NULL) {
+			syslog(LOG_ERR,
+		    	"<%s> failed to open the pid log file, run anyway.",
+		    	__func__);
+		} else {
+			fprintf(pidfp, "%d\n", pid);
+			fclose(pidfp);
+		}
+	} else {			
+		if ((pidfp = fopen(pidfilecust, "w")) == NULL) {
+			syslog(LOG_ERR,
+		    	"<%s> failed to open the pid log file, run anyway.",
+		    	__func__);
+		} else {
+			fprintf(pidfp, "%d\n", pid);
+			fclose(pidfp);
+		}
 	}
 
 #ifdef HAVE_POLL_H
@@ -297,6 +312,8 @@
 		}
 
 		if (do_die) {
+			/* unlink() pid file before exiting... */
+			if (!pidfilename)	{	unlink(pidfilecust); } else {	unlink(pidfilename); }
 			die();
 			/*NOTREACHED*/
 		}


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list