diff options
author | brian <brian@FreeBSD.org> | 1997-06-23 23:10:13 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1997-06-23 23:10:13 +0000 |
commit | a3c9607200fa5d73b5ca5d98520f8b3ed827bcad (patch) | |
tree | a1d537c05bf29eed0619e803fdc4bb0b59c7c648 /usr.sbin | |
parent | d1c718d9c36fb450a5075b50919dc171fadc6089 (diff) | |
download | FreeBSD-src-a3c9607200fa5d73b5ca5d98520f8b3ed827bcad.zip FreeBSD-src-a3c9607200fa5d73b5ca5d98520f8b3ed827bcad.tar.gz |
o Fix uptime for direct connections.
o Style police
o Make hangup abort the current connection, not
necessarily exiting (-auto/-ddial).
o Trap HUP and INT during DoChat and abort the
connection attempt. This means you can now
type "dial" and change your mind with ^C, or
HUP the process to stop it dialing.
Slapped into doing it by: Chuck Robey <chuckr@glue.umd.edu>
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ppp/chat.c | 69 | ||||
-rw-r--r-- | usr.sbin/ppp/command.c | 8 | ||||
-rw-r--r-- | usr.sbin/ppp/defs.h | 3 | ||||
-rw-r--r-- | usr.sbin/ppp/main.c | 42 | ||||
-rw-r--r-- | usr.sbin/ppp/modem.c | 20 |
5 files changed, 76 insertions, 66 deletions
diff --git a/usr.sbin/ppp/chat.c b/usr.sbin/ppp/chat.c index 6ba72e4..9c3984b 100644 --- a/usr.sbin/ppp/chat.c +++ b/usr.sbin/ppp/chat.c @@ -18,7 +18,7 @@ * Columbus, OH 43221 * (614)451-1883 * - * $Id: chat.c,v 1.25 1997/05/26 00:43:57 brian Exp $ + * $Id: chat.c,v 1.26 1997/06/09 03:27:15 brian Exp $ * * TODO: * o Support more UUCP compatible control sequences. @@ -40,6 +40,7 @@ #include <sys/socket.h> #include <sys/param.h> #include <netinet/in.h> +#include <setjmp.h> #include "timeout.h" #include "loadalias.h" #include "vars.h" @@ -62,9 +63,7 @@ extern int ChangeParity(char *); #define ABORT -1 static char * -findblank(p, instring) -char *p; -int instring; +findblank(char *p, int instring) { if (instring) { while (*p) { @@ -87,10 +86,7 @@ int instring; } int -MakeArgs(script, pvect, maxargs) -char *script; -char **pvect; -int maxargs; +MakeArgs(char *script, char **pvect, int maxargs) { int nargs, nb; int instring; @@ -133,11 +129,7 @@ int maxargs; * \U Auth User */ char * -ExpandString(str, result, reslen, sendmode) -char *str; -char *result; -int reslen; -int sendmode; +ExpandString(char *str, char *result, int reslen, int sendmode) { int addcr = 0; char *phone; @@ -223,12 +215,14 @@ int sendmode; static char logbuff[MAXLOGBUFF]; static int loglen = 0; -static void clear_log() { +static void clear_log() +{ memset(logbuff,0,MAXLOGBUFF); loglen = 0; } -static void flush_log() { +static void flush_log() +{ if (LogIsKept(LogCONNECT)) LogPrintf(LogCONNECT,"%s", logbuff); else if (LogIsKept(LogCARRIER) && strstr(logbuff,"CARRIER")) @@ -237,7 +231,8 @@ static void flush_log() { clear_log(); } -static void connect_log(char *str, int single_p) { +static void connect_log(char *str, int single_p) +{ int space = MAXLOGBUFF - loglen - 1; while (space--) { @@ -251,11 +246,8 @@ static void connect_log(char *str, int single_p) { if (!space) flush_log(); } - - int -WaitforString(estr) -char *estr; +WaitforString(char *estr) { struct timeval timeout; char *s, *str, ch; @@ -388,8 +380,7 @@ char *estr; } void -ExecStr(command, out) -char *command, *out; +ExecStr(char *command, char *out) { int pid; int fids[2]; @@ -466,8 +457,7 @@ char *command, *out; } void -SendString(str) -char *str; +SendString(char *str) { char *cp; int on; @@ -505,8 +495,7 @@ char *str; } int -ExpectString(str) -char *str; +ExpectString(char *str) { char *minus; int state; @@ -563,14 +552,34 @@ char *str; return(MATCH); } +static jmp_buf ChatEnv; +static void (*ohup)(int), (*oint)(int); + +static void +StopDial(int sig) +{ + LogPrintf(LogPHASE, "DoChat: Caught signal %d, abort connect\n", sig); + longjmp(ChatEnv,1); +} + int -DoChat(script) -char *script; +DoChat(char *script) { char *vector[40]; char **argv; int argc, n, state; + /* While we're chatting, we want a HUP/INT to fail us */ + if (setjmp(ChatEnv)) { + signal(SIGHUP, ohup); + signal(SIGINT, oint); + return(-1); + } + ohup = signal(SIGHUP, SIG_IGN); + oint = signal(SIGINT, SIG_IGN); + signal(SIGHUP, StopDial); + signal(SIGINT, StopDial); + timeout_next = abort_next = 0; for (n = 0; AbortStrings[n]; n++) { free(AbortStrings[n]); @@ -600,8 +609,12 @@ char *script; HangupModem(); #endif case NOMATCH: + signal(SIGHUP, ohup); + signal(SIGINT, oint); return(NOMATCH); } } + signal(SIGHUP, ohup); + signal(SIGINT, oint); return(MATCH); } diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c index f440752..18c9206 100644 --- a/usr.sbin/ppp/command.c +++ b/usr.sbin/ppp/command.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: command.c,v 1.59 1997/06/17 02:04:51 brian Exp $ + * $Id: command.c,v 1.60 1997/06/23 19:18:13 brian Exp $ * */ #include <sys/types.h> @@ -139,6 +139,7 @@ int argc; char **argv; { int tries; + int res; if (LcpFsm.state > ST_CLOSED) { if (VarTerm) @@ -167,12 +168,13 @@ char **argv; fprintf(VarTerm, "Failed to open modem.\n"); break; } - if (DialModem() == EX_DONE) { + if ((res = DialModem()) == EX_DONE) { sleep(1); ModemTimeout(); PacketMode(); break; - } + } else if (res == EX_SIG) + return 1; } while (VarDialTries == 0 || tries < VarDialTries); return 0; diff --git a/usr.sbin/ppp/defs.h b/usr.sbin/ppp/defs.h index 2b90881..937fcaf 100644 --- a/usr.sbin/ppp/defs.h +++ b/usr.sbin/ppp/defs.h @@ -15,7 +15,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: defs.h,v 1.15 1997/06/09 03:27:18 brian Exp $ + * $Id: defs.h,v 1.16 1997/06/13 02:07:29 brian Exp $ * * TODO: */ @@ -69,6 +69,7 @@ #define MODE_BACKGROUND 64 /* Background mode. */ +#define EX_SIG -1 #define EX_NORMAL 0 #define EX_START 1 #define EX_SOCK 2 diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c index c24e501..3b6c26a 100644 --- a/usr.sbin/ppp/main.c +++ b/usr.sbin/ppp/main.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: main.c,v 1.63 1997/06/16 19:59:41 brian Exp $ + * $Id: main.c,v 1.64 1997/06/17 01:46:05 brian Exp $ * * TODO: * o Add commands for traffic summary, version display, etc. @@ -82,7 +82,7 @@ static char if_filename[MAXPATHLEN]; int tunno; static void -TtyInit() +TtyInit(int DontWantInt) { struct termios newtio; int stat; @@ -97,7 +97,8 @@ TtyInit() newtio.c_iflag = 0; newtio.c_oflag &= ~OPOST; newtio.c_cc[VEOF] = _POSIX_VDISABLE; - newtio.c_cc[VINTR] = _POSIX_VDISABLE; + if (DontWantInt) + newtio.c_cc[VINTR] = _POSIX_VDISABLE; newtio.c_cc[VMIN] = 1; newtio.c_cc[VTIME] = 0; newtio.c_cflag |= CS8; @@ -198,21 +199,9 @@ static void Hangup(signo) int signo; { -#ifdef TRAPSEGV - if (signo == SIGSEGV) { - LogPrintf(LogPHASE, "Signal %d, core dump.\n", signo); - LogClose(); - abort(); - } -#endif - if (BGPid) { - kill (BGPid, SIGTERM); - exit (EX_HANGUP); - } - else { - LogPrintf(LogPHASE, "Signal %d, hangup.\n", signo); - Cleanup(EX_HANGUP); - } + /* NOTE, these are manual, we've done a setsid() */ + reconnect(RECON_FALSE); + DownConnection(); } static void @@ -387,9 +376,6 @@ char **argv; pending_signal(SIGTERM, CloseSession); pending_signal(SIGINT, CloseSession); pending_signal(SIGQUIT, CloseSession); -#ifdef TRAPSEGV - signal(SIGSEGV, Hangup); -#endif #ifdef SIGPIPE signal(SIGPIPE, SIG_IGN); #endif @@ -519,13 +505,13 @@ char **argv; #else if (mode & MODE_DIRECT) #endif - TtyInit(); + TtyInit(1); else { setsid(); close(1); } } else { - TtyInit(); + TtyInit(0); TtyCommandMode(1); } LogPrintf(LogPHASE, "PPP Started.\n"); @@ -743,6 +729,7 @@ DoLoop() int dial_up; int tries; int qlen; + int res; pid_t pgroup; pgroup = getpgrp(); @@ -834,7 +821,7 @@ DoLoop() else LogPrintf(LogCHAT, "Dial attempt %u\n", tries); - if (DialModem() == EX_DONE) { + if ((res = DialModem()) == EX_DONE) { sleep(1); /* little pause to allow peer starts */ ModemTimeout(); PacketMode(); @@ -844,13 +831,14 @@ DoLoop() } else { CloseModem(); if (mode & MODE_BACKGROUND) { - if (VarNextPhone == NULL) + if (VarNextPhone == NULL || res == EX_SIG) Cleanup(EX_DIAL); /* Tried all numbers - no luck */ else /* Try all numbers in background mode */ StartRedialTimer(VarRedialNextTimeout); - } else if (!(mode & MODE_DDIAL) && VarDialTries - && tries >= VarDialTries) { + } else if (!(mode & MODE_DDIAL) && + ((VarDialTries && tries >= VarDialTries) || + res == EX_SIG)) { /* I give up ! Can't get through :( */ StartRedialTimer(VarRedialTimeout); dial_up = FALSE; diff --git a/usr.sbin/ppp/modem.c b/usr.sbin/ppp/modem.c index b34545e..4625483 100644 --- a/usr.sbin/ppp/modem.c +++ b/usr.sbin/ppp/modem.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: modem.c,v 1.42 1997/06/09 03:27:30 brian Exp $ + * $Id: modem.c,v 1.43 1997/06/11 03:57:50 brian Exp $ * * TODO: */ @@ -207,7 +207,9 @@ void DownConnection() { LogPrintf(LogPHASE, "Disconnected!\n"); - LogPrintf(LogPHASE, "Connect time: %d secs\n", time(NULL) - uptime); + if (uptime) + LogPrintf(LogPHASE, "Connect time: %d secs\n", time(NULL) - uptime); + uptime = 0; if (!TermMode) { CloseModem(); LcpDown(); @@ -711,19 +713,23 @@ DialModem() strncpy(ScriptBuffer, VarDialScript,sizeof(ScriptBuffer)-1); ScriptBuffer[sizeof(ScriptBuffer)-1] = '\0'; - if (DoChat(ScriptBuffer) > 0) { + if ((excode = DoChat(ScriptBuffer)) > 0) { if (VarTerm) fprintf(VarTerm, "dial OK!\n"); strncpy(ScriptBuffer, VarLoginScript,sizeof(ScriptBuffer)-1); - if (DoChat(ScriptBuffer) > 0) { + if ((excode = DoChat(ScriptBuffer)) > 0) { if (VarTerm) fprintf(VarTerm, "login OK!\n"); return EX_DONE; + } else if (excode == -1) + excode = EX_SIG; + else { + LogPrintf(LogWARN, "DialModem: login failed.\n"); + excode = EX_NOLOGIN; } - LogPrintf(LogWARN, "DialModem: login failed.\n"); ModemTimeout(); /* Dummy call to check modem status */ - excode = EX_NOLOGIN; - } + } else if (excode == -1) + excode = EX_SIG; else { LogPrintf(LogWARN, "DialModem: dial failed.\n"); excode = EX_NODIAL; |