From owner-svn-src-stable@FreeBSD.ORG Tue Feb 8 11:48:47 2011 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E4C72106564A; Tue, 8 Feb 2011 11:48:47 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D3DFF8FC16; Tue, 8 Feb 2011 11:48:47 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p18BmlVZ044747; Tue, 8 Feb 2011 11:48:47 GMT (envelope-from delphij@svn.freebsd.org) Received: (from delphij@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p18BmlDS044743; Tue, 8 Feb 2011 11:48:47 GMT (envelope-from delphij@svn.freebsd.org) Message-Id: <201102081148.p18BmlDS044743@svn.freebsd.org> From: Xin LI Date: Tue, 8 Feb 2011 11:48:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r218434 - stable/7/usr.sbin/rtadvd X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Feb 2011 11:48:48 -0000 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 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 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 #include #include +#include #include #include #include @@ -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*/ }