summaryrefslogtreecommitdiffstats
path: root/libexec/pppoed
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1999-11-23 00:21:20 +0000
committerbrian <brian@FreeBSD.org>1999-11-23 00:21:20 +0000
commit3d4700ff3018349a466aa9d16ba285ccb3b6e9aa (patch)
treeb613dfa04f8dd6bf117418ba77244c1a5580e669 /libexec/pppoed
parent0490237359168cdf80cd0cb32ed68534dcf37f89 (diff)
downloadFreeBSD-src-3d4700ff3018349a466aa9d16ba285ccb3b6e9aa.zip
FreeBSD-src-3d4700ff3018349a466aa9d16ba285ccb3b6e9aa.tar.gz
Add a ``-P pidfile'' option
Diffstat (limited to 'libexec/pppoed')
-rw-r--r--libexec/pppoed/pppoed.87
-rw-r--r--libexec/pppoed/pppoed.c33
2 files changed, 37 insertions, 3 deletions
diff --git a/libexec/pppoed/pppoed.8 b/libexec/pppoed/pppoed.8
index da8038b..808c3dd 100644
--- a/libexec/pppoed/pppoed.8
+++ b/libexec/pppoed/pppoed.8
@@ -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
diff --git a/libexec/pppoed/pppoed.c b/libexec/pppoed/pppoed.c
index 31abf16..8606309 100644
--- a/libexec/pppoed/pppoed.c
+++ b/libexec/pppoed/pppoed.c
@@ -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);
OpenPOWER on IntegriCloud