From f2101f99f933cb557b9a402c7649040ae5472508 Mon Sep 17 00:00:00 2001 From: "Michael K. Johnson" Date: Thu, 23 Sep 1999 06:00:39 +0000 Subject: make ppp-watch kill leftover dialer more reliably --- src/ppp-watch.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/ppp-watch.c') diff --git a/src/ppp-watch.c b/src/ppp-watch.c index 5a0e7054..dc0454ef 100644 --- a/src/ppp-watch.c +++ b/src/ppp-watch.c @@ -211,6 +211,13 @@ fork_exec(int wait, char *path, char *arg1, char *arg2, char *arg3) if (!(child = fork())) { /* child */ + + if (!wait) { + /* make sure that pppd is in its own process group */ + setsid(); + setpgid(0, 0); + } + execl(path, path, arg1, arg2, arg3, NULL); perror(path); _exit (1); @@ -444,7 +451,10 @@ main(int argc, char **argv) { physicalDevice = pppLogicalToPhysical(&pppdPid, device); if (physicalDevice) { free(physicalDevice); physicalDevice = NULL; } kill(pppdPid, sendsig); - if (sendsig == SIGKILL) cleanExit(32); + if (sendsig == SIGKILL) { + kill(-pppdPid, sendsig); + cleanExit(32); + } } if (theSighup) { theSighup = 0; @@ -484,6 +494,16 @@ main(int argc, char **argv) { waited = wait3(&status, 0, NULL); if (waited < 0) continue; + /* now, we need to kill any children of pppd still in pppd's + * process group, in case they are hanging around. + * pppd is dead (we just waited for it) but there is no + * guarantee that its children are dead, and they will + * hold the modem if we do not get rid of them. + * We have kept the old pid/pgrp around in pppdPid. + */ + kill(-pppdPid, SIGKILL); + pppdPid = 0; + if (!WIFEXITED(status)) cleanExit(29); if (dieing) cleanExit(WEXITSTATUS(status)); -- cgit v1.2.1