From 70b5140b54a9f1c59c379a7cb1589bda282b054f Mon Sep 17 00:00:00 2001 From: "Michael K. Johnson" Date: Thu, 23 Sep 1999 16:18:45 +0000 Subject: kill nicely, try to hang up modem --- src/ppp-watch.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/ppp-watch.c b/src/ppp-watch.c index a0d708fc..fefbc8b9 100644 --- a/src/ppp-watch.c +++ b/src/ppp-watch.c @@ -73,6 +73,7 @@ #include #include #include +#include #include #include "shvar.h" @@ -347,6 +348,33 @@ interfaceStatus(char *device) { } +/* very, very minimal hangup function. This is just to attempt to + * hang up a device that should already be hung up, so it does not + * need to be bulletproof. + */ +void +hangup(shvarFile *ifcfg) { + int fd; + char *filename; + struct termios ots, ts; + + filename = svGetValue(ifcfg, "MODEMPORT"); + if (!filename) return; + fd = open(filename, O_RDWR|O_NOCTTY|O_NONBLOCK); + if (fd == -1) goto clean; + if (tcgetattr(fd, &ts)) goto clean; + ots = ts; + write(fd, "\r", 1); /* tickle modems that do not like dropped DTR */ + usleep(1000); + cfsetospeed(&ts, B0); + tcsetattr(fd, TCSANOW, &ts); + usleep(100000); + tcsetattr(fd, TCSANOW, &ots); + +clean: + free(filename); +} + @@ -453,7 +481,10 @@ main(int argc, char **argv) { if (!pppdPid) cleanExit(34); kill(pppdPid, sendsig); if (sendsig == SIGKILL) { + kill(-pppdPid, SIGTERM); /* give it a chance to die nicely */ + usleep(2500000); kill(-pppdPid, sendsig); + hangup(ifcfg); cleanExit(32); } } @@ -502,7 +533,12 @@ main(int argc, char **argv) { * hold the modem if we do not get rid of them. * We have kept the old pid/pgrp around in pppdPid. */ - if (pppdPid) kill(-pppdPid, SIGKILL); + if (pppdPid) { + kill(-pppdPid, SIGTERM); /* give it a chance to die nicely */ + usleep(2500000); + kill(-pppdPid, SIGKILL); + hangup(ifcfg); + } pppdPid = 0; if (!WIFEXITED(status)) cleanExit(29); -- cgit v1.2.1