Add a ``-P pidfile'' option

This commit is contained in:
Brian Somers 1999-11-23 00:21:20 +00:00
parent be8bbe8809
commit 97cba131dc
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=53609
2 changed files with 37 additions and 3 deletions

View File

@ -34,6 +34,7 @@
.Sh SYNOPSIS
.Nm pppoed
.Op Fl Fd
.Op Fl P Ar pidfile
.Op Fl a Ar name
.Op Fl e Ar exec
.Op Fl p Ar provider
@ -120,6 +121,12 @@ If the
flag is given, additional diagnostics are provided (see the
.Sx DIAGNOSTICS
section below).
.Pp
If
.Ar pidfile
is given,
.Nm
will write its process ID to this file on startup.
.Sh DIAGNOSTICS
After creating the necessary
.Xr netgraph 4

View File

@ -65,11 +65,13 @@
static int
usage(const char *prog)
{
fprintf(stderr, "Usage: %s [-Fd] [-a name] [-e exec] [-p provider]"
" interface\n", prog);
fprintf(stderr, "Usage: %s [-Fd] [-P pidfile] [-a name] [-e exec]"
" [-p provider] interface\n", prog);
return EX_USAGE;
}
const char *pidfile;
static void
Fairwell(int sig)
{
@ -81,6 +83,9 @@ Fairwell(int sig)
syslog(LOG_INFO, buf);
if (pidfile)
remove(pidfile);
signal(sig, SIG_DFL);
raise(sig);
}
@ -422,17 +427,22 @@ main(int argc, char **argv)
prog = strrchr(argv[0], '/');
prog = prog ? prog + 1 : argv[0];
pidfile = NULL;
exec = NULL;
acname = NULL;
provider = "";
optF = optd = 0;
while ((ch = getopt(argc, argv, "a:Fde:p:")) != -1) {
while ((ch = getopt(argc, argv, "FP:a:de:p:")) != -1) {
switch (ch) {
case 'F':
optF = 1;
break;
case 'P':
pidfile = optarg;
break;
case 'a':
acname = optarg;
break;
@ -512,9 +522,26 @@ main(int argc, char **argv)
if (!optF && daemon(1, 0) == -1) {
perror("daemon()");
close(cs);
close(ds);
return EX_OSERR;
}
if (pidfile != NULL) {
FILE *fp;
if ((fp = fopen(pidfile, "w")) == NULL) {
perror(pidfile);
close(cs);
close(ds);
return EX_CANTCREAT;
} else {
fprintf(fp, "%d\n", (int)getpid());
fclose(fp);
}
}
openlog(prog, LOG_PID | (optF ? LOG_PERROR : 0), LOG_DAEMON);
signal(SIGHUP, Fairwell);