From b35fc1356ae43ad3c82180cf8c3457e4ace8c63b Mon Sep 17 00:00:00 2001 From: "Michael K. Johnson" Date: Mon, 13 Sep 1999 01:54:08 +0000 Subject: do not run multiple copies setsid/setpgid seems to help... --- src/ppp-watch.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src') 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])) { -- cgit v1.2.1