From 46ef8a5eda67ef2fd99b75877802f0a244c6f141 Mon Sep 17 00:00:00 2001 From: "Michael K. Johnson" Date: Tue, 28 Sep 1999 20:44:49 +0000 Subject: recover if dead daemon left pidfile --- src/ppp-watch.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ppp-watch.c b/src/ppp-watch.c index 2580e0ec..44a6edd5 100644 --- a/src/ppp-watch.c +++ b/src/ppp-watch.c @@ -169,6 +169,7 @@ doPidFile(char *device) { pidFileName = device; pidFilePath = alloca(strlen(pidFileName) + 25); sprintf(pidFilePath, "/var/run/pppwatch-%s.pid", pidFileName); +restart: fd = open(pidFilePath, O_WRONLY|O_TRUNC|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR | S_IRGRP | S_IROTH); @@ -184,10 +185,16 @@ doPidFile(char *device) { */ f = fdopen(fd, "r"); if (!f) cleanExit(37); - if (fscanf(f, "%d", &pid) && pid) - kill(pid, SIGHUP); + fscanf(f, "%d", &pid); fclose(f); - cleanExit(33); + if (pid) { + if (kill(pid, SIGHUP)) { + unlink(pidFilePath); + goto restart; + } else { + cleanExit(33); + } + } } f = fdopen(fd, "w"); -- cgit v1.2.1