Allow overriding pidfile and dumpfile.
PR: bin/153362 Submitted by: Joe Holden <joe rewt org uk> MFC after: 1 month
This commit is contained in:
parent
ea23319939
commit
f49f3df86a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=216675
@ -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
|
||||
|
@ -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 printed.
|
||||
.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
|
||||
|
@ -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*/
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user