aboutsummaryrefslogtreecommitdiffstats
path: root/src/ppp-watch.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ppp-watch.c')
-rw-r--r--src/ppp-watch.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/ppp-watch.c b/src/ppp-watch.c
index ad8e2779..b3a7bb53 100644
--- a/src/ppp-watch.c
+++ b/src/ppp-watch.c
@@ -130,11 +130,36 @@ detach(int now, int parentExitCode, char *device) {
close (0);
close (1);
close (2);
+ setsid();
+ setpgid(0, 0);
}
}
}
+
+static void
+checkPidFile(char *device) {
+ char *pidFilePath;
+ FILE *f;
+ pid_t previous;
+ int killed;
+
+ pidFilePath = alloca(strlen(device) + 25);
+ sprintf(pidFilePath, "/var/run/pppwatch-%s.pid", device);
+ f = fopen(pidFilePath, "r");
+ if (f) {
+ fscanf(f, "%d\n", &previous);
+ fclose(f);
+
+ killed = kill(previous, SIGHUP);
+ if (!killed) {
+ fprintf(stderr, "%s already up, initiating redial\n", device);
+ exit(33);
+ }
+ }
+}
+
static void
doPidFile(char *device) {
static char *pidFileName = NULL;
@@ -338,6 +363,8 @@ main(int argc, char **argv) {
device = argv[1];
}
+ checkPidFile(device);
+
detach(0, 0, device); /* prepare */
if (argc > 2 && !strcmp("boot", argv[2])) {