From nobody@FreeBSD.org  Wed Dec 22 01:55:37 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 79950106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 22 Dec 2010 01:55:37 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (unknown [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 4E0968FC12
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 22 Dec 2010 01:55:37 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id oBM1tbFX028474
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 22 Dec 2010 01:55:37 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id oBM1tbUc028473;
	Wed, 22 Dec 2010 01:55:37 GMT
	(envelope-from nobody)
Message-Id: <201012220155.oBM1tbUc028473@red.freebsd.org>
Date: Wed, 22 Dec 2010 01:55:37 GMT
From: Joe Holden <joe@rewt.org.uk>
To: freebsd-gnats-submit@FreeBSD.org
Subject: patch to add -p flag to set pidfile for rtadvd
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         153362
>Category:       bin
>Synopsis:       [patch] add -p flag to set pidfile for rtadvd(8)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    delphij
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec 22 02:00:23 UTC 2010
>Closed-Date:    Tue Feb 08 11:49:37 UTC 2011
>Last-Modified:  Tue Feb  8 11:50:12 UTC 2011
>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:

From: "Joe Holden" <joe@rewt.org.uk>
To: <bug-followup@FreeBSD.org>,
	<joe@rewt.org.uk>
Cc:  
Subject: Re: bin/153362: [patch] add -p flag to set pidfile for rtadvd(8)
Date: Wed, 22 Dec 2010 16:07:36 -0000

 This is a multi-part message in MIME format.
 
 ------=_NextPart_000_0020_01CBA1F2.59A8E6B0
 Content-Type: multipart/alternative;
 	boundary="----=_NextPart_001_0021_01CBA1F2.59A8E6B0"
 
 
 ------=_NextPart_001_0021_01CBA1F2.59A8E6B0
 Content-Type: text/plain;
 	charset="iso-8859-1"
 Content-Transfer-Encoding: quoted-printable
 
 Fixed if/else ordering, only try and unlink pidfile if pidfp is set...
 
 Ta,
 J
 ------=_NextPart_001_0021_01CBA1F2.59A8E6B0
 Content-Type: text/html;
 	charset="iso-8859-1"
 Content-Transfer-Encoding: quoted-printable
 
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 <HTML><HEAD>
 <META content=3D"text/html; charset=3Diso-8859-1" =
 http-equiv=3DContent-Type>
 <META name=3DGENERATOR content=3D"MSHTML 8.00.6001.18999">
 <STYLE></STYLE>
 </HEAD>
 <BODY bgColor=3D#ffffff>
 <DIV><FONT size=3D2 face=3DArial>Fixed if/else ordering, only try and =
 unlink pidfile=20
 if pidfp is set...</FONT></DIV>
 <DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
 <DIV><FONT size=3D2 face=3DArial>Ta,</FONT></DIV>
 <DIV><FONT size=3D2 face=3DArial>J</FONT></DIV></BODY></HTML>
 
 ------=_NextPart_001_0021_01CBA1F2.59A8E6B0--
 
 ------=_NextPart_000_0020_01CBA1F2.59A8E6B0
 Content-Type: application/octet-stream;
 	name="rtadvd-releng8.patch"
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: attachment;
 	filename="rtadvd-releng8.patch"
 
 diff -ur rtadvd.orig/rtadvd.8 rtadvd/rtadvd.8=0A=
 --- rtadvd.orig/rtadvd.8	2010-12-22 01:32:38.000000000 +0000=0A=
 +++ rtadvd/rtadvd.8	2010-12-22 01:22:15.000000000 +0000=0A=
 @@ -144,6 +144,8 @@=0A=
  .It Fl s=0A=
  Do not add or delete prefixes dynamically.=0A=
  Only statically configured prefixes, if any, will be advertised.=0A=
 +.It Fl p=0A=
 +Set an alternate pidfile location.=0A=
  .El=0A=
  .Pp=0A=
  Upon receipt of signal=0A=
 diff -ur rtadvd.orig/rtadvd.c rtadvd/rtadvd.c=0A=
 --- rtadvd.orig/rtadvd.c	2010-12-22 01:32:38.000000000 +0000=0A=
 +++ rtadvd/rtadvd.c	2010-12-22 16:04:22.000000000 +0000=0A=
 @@ -81,6 +81,7 @@=0A=
  struct in6_addr in6a_site_allrouters;=0A=
  static char *dumpfilename =3D "/var/run/rtadvd.dump"; /* XXX: should be =
 configurable */=0A=
  static char *pidfilename =3D "/var/run/rtadvd.pid"; /* should be =
 configurable */=0A=
 +char *pidfilecust;=0A=
  static char *mcastif;=0A=
  int sock;=0A=
  int rtsock =3D -1;=0A=
 @@ -163,7 +164,7 @@=0A=
  	pid_t pid;=0A=
  =0A=
  	/* get command line options and arguments */=0A=
 -	while ((ch =3D getopt(argc, argv, "c:dDfM:Rs")) !=3D -1) {=0A=
 +	while ((ch =3D getopt(argc, argv, "c:dDfMp:Rs")) !=3D -1) {=0A=
  		switch (ch) {=0A=
  		case 'c':=0A=
  			conffile =3D optarg;=0A=
 @@ -189,13 +190,16 @@=0A=
  		case 's':=0A=
  			sflag =3D 1;=0A=
  			break;=0A=
 +		case 'p':=0A=
 +			pidfilecust =3D optarg;=0A=
 +			break;=0A=
  		}=0A=
  	}=0A=
  	argc -=3D optind;=0A=
  	argv +=3D optind;=0A=
  	if (argc =3D=3D 0) {=0A=
  		fprintf(stderr,=0A=
 -			"usage: rtadvd [-dDfMRs] [-c conffile] "=0A=
 +			"usage: rtadvd [-dDfMRsp] [-c conffile] "=0A=
  			"interfaces...\n");=0A=
  		exit(1);=0A=
  	}=0A=
 @@ -241,13 +245,24 @@=0A=
  =0A=
  	/* record the current PID */=0A=
  	pid =3D getpid();=0A=
 -	if ((pidfp =3D fopen(pidfilename, "w")) =3D=3D NULL) {=0A=
 -		syslog(LOG_ERR,=0A=
 -		    "<%s> failed to open the pid log file, run anyway.",=0A=
 -		    __func__);=0A=
 -	} else {=0A=
 -		fprintf(pidfp, "%d\n", pid);=0A=
 -		fclose(pidfp);=0A=
 +	if (!pidfilecust) {=0A=
 +		if ((pidfp =3D fopen(pidfilename, "w")) =3D=3D NULL) {=0A=
 +			syslog(LOG_ERR,=0A=
 +		    	"<%s> failed to open the pid log file, run anyway.",=0A=
 +		    	__func__);=0A=
 +		} else {=0A=
 +			fprintf(pidfp, "%d\n", pid);=0A=
 +			fclose(pidfp);=0A=
 +		}=0A=
 +	} else {			=0A=
 +		if ((pidfp =3D fopen(pidfilecust, "w")) =3D=3D NULL) {=0A=
 +			syslog(LOG_ERR,=0A=
 +		    	"<%s> failed to open the pid log file, run anyway.",=0A=
 +		    	__func__);=0A=
 +		} else {=0A=
 +			fprintf(pidfp, "%d\n", pid);=0A=
 +			fclose(pidfp);=0A=
 +		}=0A=
  	}=0A=
  =0A=
  #ifdef HAVE_POLL_H=0A=
 @@ -297,6 +312,10 @@=0A=
  		}=0A=
  =0A=
  		if (do_die) {=0A=
 +			if (pidfp)	{=0A=
 +				/* unlink() pid file before exiting... */=0A=
 +				if (!pidfilecust)	{	unlink(pidfilename); } else {	=
 unlink(pidfilecust); }=0A=
 +			}=0A=
  			die();=0A=
  			/*NOTREACHED*/=0A=
  		}=0A=
 
 ------=_NextPart_000_0020_01CBA1F2.59A8E6B0--
 
State-Changed-From-To: open->patched 
State-Changed-By: delphij 
State-Changed-When: Wed Dec 22 23:58:34 UTC 2010 
State-Changed-Why:  
Applied against -HEAD (with changes). 


Responsible-Changed-From-To: freebsd-bugs->delphij 
Responsible-Changed-By: delphij 
Responsible-Changed-When: Wed Dec 22 23:58:34 UTC 2010 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=153362 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/153362: commit references a PR
Date: Wed, 22 Dec 2010 23:58:28 +0000 (UTC)

 Author: delphij
 Date: Wed Dec 22 23:58:21 2010
 New Revision: 216675
 URL: http://svn.freebsd.org/changeset/base/216675
 
 Log:
   Allow overriding pidfile and dumpfile.
   
   PR:		bin/153362
   Submitted by:	Joe Holden <joe rewt org uk>
   MFC after:	1 month
 
 Modified:
   head/usr.sbin/rtadvd/Makefile
   head/usr.sbin/rtadvd/rtadvd.8
   head/usr.sbin/rtadvd/rtadvd.c
 
 Modified: head/usr.sbin/rtadvd/Makefile
 ==============================================================================
 --- head/usr.sbin/rtadvd/Makefile	Wed Dec 22 20:27:20 2010	(r216674)
 +++ head/usr.sbin/rtadvd/Makefile	Wed Dec 22 23:58:21 2010	(r216675)
 @@ -18,6 +18,9 @@ PROG=	rtadvd
  MAN=	rtadvd.conf.5 rtadvd.8
  SRCS=	rtadvd.c rrenum.c advcap.c if.c config.c timer.c dump.c
  
 +DPADD=  ${LIBUTIL}
 +LDADD=  -lutil
 +
  CFLAGS+= -DHAVE_ARC4RANDOM -DHAVE_POLL_H -DROUTEINFO
  
  WARNS?=	1
 
 Modified: head/usr.sbin/rtadvd/rtadvd.8
 ==============================================================================
 --- head/usr.sbin/rtadvd/rtadvd.8	Wed Dec 22 20:27:20 2010	(r216674)
 +++ head/usr.sbin/rtadvd/rtadvd.8	Wed Dec 22 23:58:21 2010	(r216675)
 @@ -29,7 +29,7 @@
  .\"
  .\" $FreeBSD$
  .\"
 -.Dd May 17, 1998
 +.Dd December 22, 2010
  .Dt RTADVD 8
  .Os
  .Sh NAME
 @@ -39,6 +39,8 @@
  .Nm
  .Op Fl dDfMRs
  .Op Fl c Ar configfile
 +.Op Fl F Ar dumpfile
 +.Op Fl p Ar pidfile
  .Ar interface ...
  .Sh DESCRIPTION
  .Nm
 @@ -126,6 +128,13 @@ Even more debugging information is print
  .It Fl f
  Foreground mode (useful when debugging).
  Log messages will be dumped to stderr when this option is specified.
 +.It Fl F
 +Specify an alternative file in which to dump internal states when
 +.Nm
 +receives signal
 +.Dv SIGUSR1 .
 +The default is
 +.Pa /var/run/rtadvd.dump .
  .It Fl M
  Specify an interface to join the all-routers site-local multicast group.
  By default,
 @@ -135,6 +144,10 @@ line.
  This option has meaning only with the
  .Fl R
  option, which enables routing renumbering protocol support.
 +.It Fl p
 +Specify an alternative file in which to store the process ID.
 +The default is
 +.Pa /var/run/rtadvd.pid.
  .It Fl R
  Accept router renumbering requests.
  If you enable it, certain IPsec setup is suggested for security reasons.
 @@ -150,7 +163,9 @@ Upon receipt of signal
  .Dv SIGUSR1 ,
  .Nm
  will dump the current internal state into
 -.Pa /var/run/rtadvd.dump .
 +.Pa /var/run/rtadvd.dump
 +or the file specified with option
 +.Fl F .
  .Pp
  Use
  .Dv SIGTERM
 @@ -167,10 +182,9 @@ to all the interfaces
  .It Pa /etc/rtadvd.conf
  The default configuration file.
  .It Pa /var/run/rtadvd.pid
 -contains the pid of the currently running
 -.Nm .
 +The default process ID file.
  .It Pa /var/run/rtadvd.dump
 -The file in which
 +The default file in which
  .Nm
  dumps its internal state.
  .El
 
 Modified: head/usr.sbin/rtadvd/rtadvd.c
 ==============================================================================
 --- head/usr.sbin/rtadvd/rtadvd.c	Wed Dec 22 20:27:20 2010	(r216674)
 +++ head/usr.sbin/rtadvd/rtadvd.c	Wed Dec 22 23:58:21 2010	(r216675)
 @@ -51,6 +51,7 @@
  #include <stdio.h>
  #include <err.h>
  #include <errno.h>
 +#include <libutil.h>
  #include <string.h>
  #include <stdlib.h>
  #include <syslog.h>
 @@ -79,8 +80,9 @@ struct iovec sndiov[2];
  struct sockaddr_in6 rcvfrom;
  struct sockaddr_in6 sin6_allnodes = {sizeof(sin6_allnodes), AF_INET6};
  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 */
 +static char *dumpfilename = "/var/run/rtadvd.dump";
 +static char *pidfilename = "/var/run/rtadvd.pid";
 +static struct pidfh *pfh;
  static char *mcastif;
  int sock;
  int rtsock = -1;
 @@ -159,11 +161,10 @@ main(argc, argv)
  	struct timeval *timeout;
  	int i, ch;
  	int fflag = 0, logopt;
 -	FILE *pidfp;
 -	pid_t pid;
 +	pid_t pid, otherpid;
  
  	/* get command line options and arguments */
 -	while ((ch = getopt(argc, argv, "c:dDfM:Rs")) != -1) {
 +	while ((ch = getopt(argc, argv, "c:dDF:fMp:Rs")) != -1) {
  		switch (ch) {
  		case 'c':
  			conffile = optarg;
 @@ -189,6 +190,12 @@ main(argc, argv)
  		case 's':
  			sflag = 1;
  			break;
 +		case 'p':
 +			pidfilename = optarg;
 +			break;
 +		case 'F':
 +			dumpfilename = optarg;
 +			break;
  		}
  	}
  	argc -= optind;
 @@ -196,7 +203,7 @@ main(argc, argv)
  	if (argc == 0) {
  		fprintf(stderr,
  			"usage: rtadvd [-dDfMRs] [-c conffile] "
 -			"interfaces...\n");
 +			"[-F dumpfile] [-p pidfile] interfaces...\n");
  		exit(1);
  	}
  
 @@ -234,6 +241,16 @@ main(argc, argv)
  		exit(1);
  	}
  
 +	pfh = pidfile_open(pidfilename, 0600, &otherpid);
 +	if (pfh == NULL) {
 +		if (errno == EEXIST)
 +			errx(1, "%s already running, pid: %d",
 +			    getprogname(), otherpid);
 +		syslog(LOG_ERR,
 +		    "<%s> failed to open the pid log file, run anyway.",
 +		    __func__);
 +	}
 +
  	if (!fflag)
  		daemon(1, 0);
  
 @@ -241,14 +258,7 @@ main(argc, argv)
  
  	/* 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);
 -	}
 +	pidfile_write(pfh);
  
  #ifdef HAVE_POLL_H
  	set[0].fd = sock;
 @@ -383,6 +393,7 @@ die()
  			ra_output(ra);
  		sleep(MIN_DELAY_BETWEEN_RAS);
  	}
 +	pidfile_remove(pfh);
  	exit(0);
  	/*NOTREACHED*/
  }
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: delphij 
State-Changed-When: Tue Feb 8 11:49:13 UTC 2011 
State-Changed-Why:  
Applied against 8-STABLE and 7-STABLE, thanks for your submission! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=153362 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/153362: commit references a PR
Date: Tue,  8 Feb 2011 11:48:45 +0000 (UTC)

 Author: delphij
 Date: Tue Feb  8 11:48:37 2011
 New Revision: 218433
 URL: http://svn.freebsd.org/changeset/base/218433
 
 Log:
   MFC r216675:
   
   Allow overriding pidfile and dumpfile.
   
   PR:		bin/153362
   Submitted by:	Joe Holden <joe rewt org uk>
 
 Modified:
   stable/8/usr.sbin/rtadvd/Makefile
   stable/8/usr.sbin/rtadvd/rtadvd.8
   stable/8/usr.sbin/rtadvd/rtadvd.c
 Directory Properties:
   stable/8/usr.sbin/rtadvd/   (props changed)
 
 Modified: stable/8/usr.sbin/rtadvd/Makefile
 ==============================================================================
 --- stable/8/usr.sbin/rtadvd/Makefile	Tue Feb  8 11:32:22 2011	(r218432)
 +++ stable/8/usr.sbin/rtadvd/Makefile	Tue Feb  8 11:48:37 2011	(r218433)
 @@ -18,6 +18,9 @@ PROG=	rtadvd
  MAN=	rtadvd.conf.5 rtadvd.8
  SRCS=	rtadvd.c rrenum.c advcap.c if.c config.c timer.c dump.c
  
 +DPADD=  ${LIBUTIL}
 +LDADD=  -lutil
 +
  CFLAGS+= -DHAVE_ARC4RANDOM -DHAVE_POLL_H -DROUTEINFO
  
  .include <bsd.prog.mk>
 
 Modified: stable/8/usr.sbin/rtadvd/rtadvd.8
 ==============================================================================
 --- stable/8/usr.sbin/rtadvd/rtadvd.8	Tue Feb  8 11:32:22 2011	(r218432)
 +++ stable/8/usr.sbin/rtadvd/rtadvd.8	Tue Feb  8 11:48:37 2011	(r218433)
 @@ -29,7 +29,7 @@
  .\"
  .\" $FreeBSD$
  .\"
 -.Dd May 17, 1998
 +.Dd December 22, 2010
  .Dt RTADVD 8
  .Os
  .Sh NAME
 @@ -39,6 +39,8 @@
  .Nm
  .Op Fl dDfMRs
  .Op Fl c Ar configfile
 +.Op Fl F Ar dumpfile
 +.Op Fl p Ar pidfile
  .Ar interface ...
  .Sh DESCRIPTION
  .Nm
 @@ -126,6 +128,13 @@ Even more debugging information is print
  .It Fl f
  Foreground mode (useful when debugging).
  Log messages will be dumped to stderr when this option is specified.
 +.It Fl F
 +Specify an alternative file in which to dump internal states when
 +.Nm
 +receives signal
 +.Dv SIGUSR1 .
 +The default is
 +.Pa /var/run/rtadvd.dump .
  .It Fl M
  Specify an interface to join the all-routers site-local multicast group.
  By default,
 @@ -135,6 +144,10 @@ line.
  This option has meaning only with the
  .Fl R
  option, which enables routing renumbering protocol support.
 +.It Fl p
 +Specify an alternative file in which to store the process ID.
 +The default is
 +.Pa /var/run/rtadvd.pid.
  .It Fl R
  Accept router renumbering requests.
  If you enable it, certain IPsec setup is suggested for security reasons.
 @@ -150,7 +163,9 @@ Upon receipt of signal
  .Dv SIGUSR1 ,
  .Nm
  will dump the current internal state into
 -.Pa /var/run/rtadvd.dump .
 +.Pa /var/run/rtadvd.dump
 +or the file specified with option
 +.Fl F .
  .Pp
  Use
  .Dv SIGTERM
 @@ -167,10 +182,9 @@ to all the interfaces
  .It Pa /etc/rtadvd.conf
  The default configuration file.
  .It Pa /var/run/rtadvd.pid
 -contains the pid of the currently running
 -.Nm .
 +The default process ID file.
  .It Pa /var/run/rtadvd.dump
 -The file in which
 +The default file in which
  .Nm
  dumps its internal state.
  .El
 
 Modified: stable/8/usr.sbin/rtadvd/rtadvd.c
 ==============================================================================
 --- stable/8/usr.sbin/rtadvd/rtadvd.c	Tue Feb  8 11:32:22 2011	(r218432)
 +++ stable/8/usr.sbin/rtadvd/rtadvd.c	Tue Feb  8 11:48:37 2011	(r218433)
 @@ -51,6 +51,7 @@
  #include <stdio.h>
  #include <err.h>
  #include <errno.h>
 +#include <libutil.h>
  #include <string.h>
  #include <stdlib.h>
  #include <syslog.h>
 @@ -79,8 +80,9 @@ struct iovec sndiov[2];
  struct sockaddr_in6 rcvfrom;
  struct sockaddr_in6 sin6_allnodes = {sizeof(sin6_allnodes), AF_INET6};
  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 */
 +static char *dumpfilename = "/var/run/rtadvd.dump";
 +static char *pidfilename = "/var/run/rtadvd.pid";
 +static struct pidfh *pfh;
  static char *mcastif;
  int sock;
  int rtsock = -1;
 @@ -159,11 +161,10 @@ main(argc, argv)
  	struct timeval *timeout;
  	int i, ch;
  	int fflag = 0, logopt;
 -	FILE *pidfp;
 -	pid_t pid;
 +	pid_t pid, otherpid;
  
  	/* get command line options and arguments */
 -	while ((ch = getopt(argc, argv, "c:dDfM:Rs")) != -1) {
 +	while ((ch = getopt(argc, argv, "c:dDF:fMp:Rs")) != -1) {
  		switch (ch) {
  		case 'c':
  			conffile = optarg;
 @@ -189,6 +190,12 @@ main(argc, argv)
  		case 's':
  			sflag = 1;
  			break;
 +		case 'p':
 +			pidfilename = optarg;
 +			break;
 +		case 'F':
 +			dumpfilename = optarg;
 +			break;
  		}
  	}
  	argc -= optind;
 @@ -196,7 +203,7 @@ main(argc, argv)
  	if (argc == 0) {
  		fprintf(stderr,
  			"usage: rtadvd [-dDfMRs] [-c conffile] "
 -			"interfaces...\n");
 +			"[-F dumpfile] [-p pidfile] interfaces...\n");
  		exit(1);
  	}
  
 @@ -234,6 +241,16 @@ main(argc, argv)
  		exit(1);
  	}
  
 +	pfh = pidfile_open(pidfilename, 0600, &otherpid);
 +	if (pfh == NULL) {
 +		if (errno == EEXIST)
 +			errx(1, "%s already running, pid: %d",
 +			    getprogname(), otherpid);
 +		syslog(LOG_ERR,
 +		    "<%s> failed to open the pid log file, run anyway.",
 +		    __func__);
 +	}
 +
  	if (!fflag)
  		daemon(1, 0);
  
 @@ -241,14 +258,7 @@ main(argc, argv)
  
  	/* 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);
 -	}
 +	pidfile_write(pfh);
  
  #ifdef HAVE_POLL_H
  	set[0].fd = sock;
 @@ -383,6 +393,7 @@ die()
  			ra_output(ra);
  		sleep(MIN_DELAY_BETWEEN_RAS);
  	}
 +	pidfile_remove(pfh);
  	exit(0);
  	/*NOTREACHED*/
  }
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/153362: commit references a PR
Date: Tue,  8 Feb 2011 11:48:53 +0000 (UTC)

 Author: delphij
 Date: Tue Feb  8 11:48:47 2011
 New Revision: 218434
 URL: http://svn.freebsd.org/changeset/base/218434
 
 Log:
   MFC r216675:
   
   Allow overriding pidfile and dumpfile.
   
   PR:		bin/153362
   Submitted by:	Joe Holden <joe rewt org uk>
 
 Modified:
   stable/7/usr.sbin/rtadvd/Makefile
   stable/7/usr.sbin/rtadvd/rtadvd.8
   stable/7/usr.sbin/rtadvd/rtadvd.c
 Directory Properties:
   stable/7/usr.sbin/rtadvd/   (props changed)
 
 Modified: stable/7/usr.sbin/rtadvd/Makefile
 ==============================================================================
 --- stable/7/usr.sbin/rtadvd/Makefile	Tue Feb  8 11:48:37 2011	(r218433)
 +++ stable/7/usr.sbin/rtadvd/Makefile	Tue Feb  8 11:48:47 2011	(r218434)
 @@ -18,6 +18,9 @@ PROG=	rtadvd
  MAN=	rtadvd.conf.5 rtadvd.8
  SRCS=	rtadvd.c rrenum.c advcap.c if.c config.c timer.c dump.c
  
 +DPADD=  ${LIBUTIL}
 +LDADD=  -lutil
 +
  CFLAGS+= -DHAVE_ARC4RANDOM -DHAVE_POLL_H -DROUTEINFO
  
  .include <bsd.prog.mk>
 
 Modified: stable/7/usr.sbin/rtadvd/rtadvd.8
 ==============================================================================
 --- stable/7/usr.sbin/rtadvd/rtadvd.8	Tue Feb  8 11:48:37 2011	(r218433)
 +++ stable/7/usr.sbin/rtadvd/rtadvd.8	Tue Feb  8 11:48:47 2011	(r218434)
 @@ -29,7 +29,7 @@
  .\"
  .\" $FreeBSD$
  .\"
 -.Dd May 17, 1998
 +.Dd December 22, 2010
  .Dt RTADVD 8
  .Os
  .Sh NAME
 @@ -39,6 +39,8 @@
  .Nm
  .Op Fl dDfMRs
  .Op Fl c Ar configfile
 +.Op Fl F Ar dumpfile
 +.Op Fl p Ar pidfile
  .Ar interface ...
  .Sh DESCRIPTION
  .Nm
 @@ -126,6 +128,13 @@ Even more debugging information is print
  .It Fl f
  Foreground mode (useful when debugging).
  Log messages will be dumped to stderr when this option is specified.
 +.It Fl F
 +Specify an alternative file in which to dump internal states when
 +.Nm
 +receives signal
 +.Dv SIGUSR1 .
 +The default is
 +.Pa /var/run/rtadvd.dump .
  .It Fl M
  Specify an interface to join the all-routers site-local multicast group.
  By default,
 @@ -135,6 +144,10 @@ line.
  This option has meaning only with the
  .Fl R
  option, which enables routing renumbering protocol support.
 +.It Fl p
 +Specify an alternative file in which to store the process ID.
 +The default is
 +.Pa /var/run/rtadvd.pid.
  .It Fl R
  Accept router renumbering requests.
  If you enable it, certain IPsec setup is suggested for security reasons.
 @@ -150,7 +163,9 @@ Upon receipt of signal
  .Dv SIGUSR1 ,
  .Nm
  will dump the current internal state into
 -.Pa /var/run/rtadvd.dump .
 +.Pa /var/run/rtadvd.dump
 +or the file specified with option
 +.Fl F .
  .Pp
  Use
  .Dv SIGTERM
 @@ -169,10 +184,9 @@ to all the interfaces
  .It Pa /etc/rtadvd.conf
  The default configuration file.
  .It Pa /var/run/rtadvd.pid
 -contains the pid of the currently running
 -.Nm .
 +The default process ID file.
  .It Pa /var/run/rtadvd.dump
 -The file in which
 +The default file in which
  .Nm
  dumps its internal state.
  .El
 
 Modified: stable/7/usr.sbin/rtadvd/rtadvd.c
 ==============================================================================
 --- stable/7/usr.sbin/rtadvd/rtadvd.c	Tue Feb  8 11:48:37 2011	(r218433)
 +++ stable/7/usr.sbin/rtadvd/rtadvd.c	Tue Feb  8 11:48:47 2011	(r218434)
 @@ -51,6 +51,7 @@
  #include <stdio.h>
  #include <err.h>
  #include <errno.h>
 +#include <libutil.h>
  #include <string.h>
  #include <stdlib.h>
  #include <syslog.h>
 @@ -79,8 +80,9 @@ struct iovec sndiov[2];
  struct sockaddr_in6 rcvfrom;
  struct sockaddr_in6 sin6_allnodes = {sizeof(sin6_allnodes), AF_INET6};
  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 */
 +static char *dumpfilename = "/var/run/rtadvd.dump";
 +static char *pidfilename = "/var/run/rtadvd.pid";
 +static struct pidfh *pfh;
  static char *mcastif;
  int sock;
  int rtsock = -1;
 @@ -159,11 +161,10 @@ main(argc, argv)
  	struct timeval *timeout;
  	int i, ch;
  	int fflag = 0, logopt;
 -	FILE *pidfp;
 -	pid_t pid;
 +	pid_t pid, otherpid;
  
  	/* get command line options and arguments */
 -	while ((ch = getopt(argc, argv, "c:dDfM:Rs")) != -1) {
 +	while ((ch = getopt(argc, argv, "c:dDF:fMp:Rs")) != -1) {
  		switch (ch) {
  		case 'c':
  			conffile = optarg;
 @@ -189,6 +190,12 @@ main(argc, argv)
  		case 's':
  			sflag = 1;
  			break;
 +		case 'p':
 +			pidfilename = optarg;
 +			break;
 +		case 'F':
 +			dumpfilename = optarg;
 +			break;
  		}
  	}
  	argc -= optind;
 @@ -196,7 +203,7 @@ main(argc, argv)
  	if (argc == 0) {
  		fprintf(stderr,
  			"usage: rtadvd [-dDfMRs] [-c conffile] "
 -			"interfaces...\n");
 +			"[-F dumpfile] [-p pidfile] interfaces...\n");
  		exit(1);
  	}
  
 @@ -234,6 +241,16 @@ main(argc, argv)
  		exit(1);
  	}
  
 +	pfh = pidfile_open(pidfilename, 0600, &otherpid);
 +	if (pfh == NULL) {
 +		if (errno == EEXIST)
 +			errx(1, "%s already running, pid: %d",
 +			    getprogname(), otherpid);
 +		syslog(LOG_ERR,
 +		    "<%s> failed to open the pid log file, run anyway.",
 +		    __func__);
 +	}
 +
  	if (!fflag)
  		daemon(1, 0);
  
 @@ -241,14 +258,7 @@ main(argc, argv)
  
  	/* 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);
 -	}
 +	pidfile_write(pfh);
  
  #ifdef HAVE_POLL_H
  	set[0].fd = sock;
 @@ -383,6 +393,7 @@ die()
  			ra_output(ra);
  		sleep(MIN_DELAY_BETWEEN_RAS);
  	}
 +	pidfile_remove(pfh);
  	exit(0);
  	/*NOTREACHED*/
  }
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
