Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 8 Feb 2011 11:48:47 +0000 (UTC)
From:      Xin LI <delphij@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org
Subject:   svn commit: r218434 - stable/7/usr.sbin/rtadvd
Message-ID:  <201102081148.p18BmlDS044743@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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*/
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201102081148.p18BmlDS044743>