aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael K. Johnson <johnsonm@redhat.com>1999-09-13 01:54:08 +0000
committerMichael K. Johnson <johnsonm@redhat.com>1999-09-13 01:54:08 +0000
commitb35fc1356ae43ad3c82180cf8c3457e4ace8c63b (patch)
treebae9e08d292ac67cf5b3933e1777b3224516955c /src
parent7d349f0491187533c82fcce5d4b1cd14b2441fdd (diff)
downloadinitscripts-b35fc1356ae43ad3c82180cf8c3457e4ace8c63b.tar
initscripts-b35fc1356ae43ad3c82180cf8c3457e4ace8c63b.tar.gz
initscripts-b35fc1356ae43ad3c82180cf8c3457e4ace8c63b.tar.bz2
initscripts-b35fc1356ae43ad3c82180cf8c3457e4ace8c63b.tar.xz
initscripts-b35fc1356ae43ad3c82180cf8c3457e4ace8c63b.zip
do not run multiple copies
setsid/setpgid seems to help...
Diffstat (limited to 'src')
-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])) {