diff options
author | amurai <amurai@FreeBSD.org> | 1995-04-16 13:38:39 +0000 |
---|---|---|
committer | amurai <amurai@FreeBSD.org> | 1995-04-16 13:38:39 +0000 |
commit | 77fb3e11a9e3cb49e06bada07db0087ce92dbe4c (patch) | |
tree | 3b7c457ee92323830e7814c72b7f3e80226d0dd0 /usr.sbin | |
parent | a2b0c379b4708d88895945ad3a79a5c2f163d3ed (diff) | |
download | FreeBSD-src-77fb3e11a9e3cb49e06bada07db0087ce92dbe4c.zip FreeBSD-src-77fb3e11a9e3cb49e06bada07db0087ce92dbe4c.tar.gz |
Fixing follows and John's fruent explnation than my English....
The first problem I found was that descriptor 0 was being closed.
This happens because the modem variable is set to 0 to indicate
that it is not valid but there are not enough tests for the modem
variable being 0. You can see where I have done this in the patch.
Code in OpenModem() dups the modem descriptor if it is < 3. Once
this happened the modem was always open and an incomming call would
have getty and ppp reading the modem.
Descriptor 1 is closed when the quit command was executed from a
telnet connection. The next modem open returns descriptor 1
and this gets duped leaving the modem always open again.
The modem was not being closed when the connection dropped or was
closed from the other end. The UUCP lock was also not removed if
the modem could not be opened.
Reviewed by: Atsushi Murai <amurai@spec.co.jp>
Submitted by: John Capo <jc@irbs.com>
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ppp/command.c | 3 | ||||
-rw-r--r-- | usr.sbin/ppp/modem.c | 36 |
2 files changed, 32 insertions, 7 deletions
diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c index bcd14e0..b926879 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.2 1995/02/26 12:17:22 amurai Exp $ + * $Id: command.c,v 1.3 1995/02/27 10:57:45 amurai Exp $ * */ #include <ctype.h> @@ -445,6 +445,7 @@ char **argv; VarLocalAuth = LOCAL_NO_AUTH; close(netfd); close(1); + dup2(2, 1); /* Have to have something here or the modem will be 1 */ netfd = -1; mode &= ~MODE_INTER; } diff --git a/usr.sbin/ppp/modem.c b/usr.sbin/ppp/modem.c index b056a83..5595bc9 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.3 1995/02/27 10:57:54 amurai Exp $ + * $Id: modem.c,v 1.4 1995/03/11 15:18:48 amurai Exp $ * * TODO: */ @@ -208,6 +208,7 @@ DownConnection() { LogPrintf(LOG_PHASE, "Disconnected!\n"); LogPrintf(LOG_PHASE, "Connect time: %d secs\n", time(NULL) - uptime); + CloseModem(); LcpDown(); connect_time = 0; } @@ -381,6 +382,7 @@ int mode; modem = open(VarDevice, O_RDWR|O_NONBLOCK); if (modem < 0) { LogPrintf(LOG_PHASE, "Open Failed %s\n", VarDevice); + (void) uu_unlock(uucplock); return(modem); } } else { @@ -403,8 +405,20 @@ int mode; } } + /* This code gets around the problem of closing descriptor 0 + * when it should not have been closed and closing descriptor 1 + * when the telnet connection dies. Since this program always + * opens a descriptor for the modem in auto and direct mode, + * having to dup the descriptor here is a fatal error. + * + * With the other changes I have made this should no longer happen. + * JC + */ while (modem < 3) + { + logprintf("Duping modem fd %d\n", modem); modem = dup(modem); + } /* * If we are working on tty device, change it's mode into @@ -562,9 +576,16 @@ int flag; if (modem && (flag || !(mode & MODE_DEDICATED))) { ModemTimeout(); /* XXX */ StopTimer(&ModemTimer); /* XXX */ - tcflush(modem, TIOCFLUSH); - UnrawModem(modem); - close(modem); + + /* ModemTimeout() may call DownConection() to close the modem + * resulting in modem == 0. + */ + if (modem) + { + tcflush(modem, TIOCFLUSH); + UnrawModem(modem); + close(modem); + } (void) uu_unlock(uucplock); modem = 0; /* Mark as modem has closed */ } else if (modem) { @@ -581,8 +602,11 @@ int flag; CloseModem() { - close(modem); - modem = 0; + if (modem >= 3) + { + close(modem); + modem = 0; + } (void) uu_unlock(uucplock); } |