From 6cc74912ac69928134b22c8720035bd8a64c7e08 Mon Sep 17 00:00:00 2001 From: brian Date: Sun, 10 Jan 1999 02:23:23 +0000 Subject: Only call isatty() when we open our descriptor, and remember the answer. If we later get a descriptor exception from select(), we know that it's a tty (isatty() returns 0 after the exception on a tty) and remember to call modem_LogicalClose(). The upshot of it all is that descriptor exceptions dont leave the tty locked any more. --- usr.sbin/ppp/ppp/modem.c | 25 +++++++++++++------------ usr.sbin/ppp/ppp/physical.c | 9 ++------- usr.sbin/ppp/ppp/physical.h | 9 ++------- 3 files changed, 17 insertions(+), 26 deletions(-) (limited to 'usr.sbin/ppp') diff --git a/usr.sbin/ppp/ppp/modem.c b/usr.sbin/ppp/ppp/modem.c index 34ec8945f97..7dacede5c9b 100644 --- a/usr.sbin/ppp/ppp/modem.c +++ b/usr.sbin/ppp/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.1 1998/08/31 00:22:24 brian Exp $ + * $Id: modem.c,v 1.2 1999/01/10 02:23:22 brian Exp $ * * TODO: */ @@ -115,7 +115,7 @@ modem_Create(struct datalink *dl, int type) p->fd = -1; p->mbits = 0; - p->dev_is_modem = 0; + p->isatty = 0; p->out = NULL; p->connect_count = 0; p->dl = dl; @@ -276,7 +276,7 @@ modem_Timeout(void *data) timer_Stop(&modem->Timer); timer_Start(&modem->Timer); - if (modem->dev_is_modem) { + if (modem->isatty || physical_IsSync(modem)) { if (modem->fd >= 0) { if (ioctl(modem->fd, TIOCMGET, &modem->mbits) < 0) { log_Printf(LogPHASE, "%s: ioctl error (%s)!\n", modem->link.name, @@ -617,8 +617,8 @@ modem_Open(struct physical *modem, struct bundle *bundle) * for further operation. */ modem->mbits = 0; - modem->dev_is_modem = isatty(modem->fd) || physical_IsSync(modem); - if (modem->dev_is_modem && !physical_IsSync(modem)) { + modem->isatty = isatty(modem->fd); + if (modem->isatty) { tcgetattr(modem->fd, &rstio); modem->ios = rstio; log_Printf(LogDEBUG, "%s: Open: modem (get): fd = %d, iflag = %lx, " @@ -679,7 +679,7 @@ modem_Speed(struct physical *modem) { struct termios rstio; - if (!physical_IsATTY(modem)) + if (!modem->isatty) return 115200; tcgetattr(modem->fd, &rstio); @@ -697,7 +697,7 @@ modem_Raw(struct physical *modem, struct bundle *bundle) log_Printf(LogDEBUG, "%s: Entering modem_Raw\n", modem->link.name); - if (!isatty(modem->fd) || physical_IsSync(modem)) + if (!modem->isatty || physical_IsSync(modem)) return 0; if (modem->type != PHYS_DIRECT && modem->fd >= 0 && !Online(modem)) @@ -721,7 +721,8 @@ modem_Raw(struct physical *modem, struct bundle *bundle) return (-1); fcntl(modem->fd, F_SETFL, oldflag | O_NONBLOCK); - if (modem->dev_is_modem && ioctl(modem->fd, TIOCMGET, &modem->mbits) == 0 && + if ((modem->isatty || physical_IsSync(modem)) && + ioctl(modem->fd, TIOCMGET, &modem->mbits) == 0 && (modem->mbits & TIOCM_CD)) { modem_StartTimer(bundle, modem); modem_Timeout(modem); @@ -737,7 +738,7 @@ modem_Unraw(struct physical *modem) { int oldflag; - if (isatty(modem->fd) && !physical_IsSync(modem)) { + if (modem->isatty && !physical_IsSync(modem)) { tcsetattr(modem->fd, TCSAFLUSH, &modem->ios); oldflag = fcntl(modem->fd, F_GETFL, 0); if (oldflag < 0) @@ -775,7 +776,7 @@ modem_Offline(struct physical *modem) timer_Stop(&modem->Timer); modem->mbits &= ~TIOCM_DTR; - if (isatty(modem->fd) && Online(modem)) { + if (modem->isatty && Online(modem)) { tcgetattr(modem->fd, &tio); if (cfsetspeed(&tio, B0) == -1) log_Printf(LogWARN, "%s: Unable to set modem to speed 0\n", @@ -796,7 +797,7 @@ modem_Close(struct physical *modem) log_Printf(LogDEBUG, "%s: Close\n", modem->link.name); - if (!isatty(modem->fd)) { + if (!modem->isatty) { modem_PhysicalClose(modem); *modem->name.full = '\0'; modem->name.base = modem->name.full; @@ -876,7 +877,7 @@ modem_ShowStatus(struct cmdargs const *arg) prompt_Printf(arg->prompt, "Name: %s\n", modem->link.name); prompt_Printf(arg->prompt, " State: "); if (modem->fd >= 0) { - if (isatty(modem->fd)) + if (modem->isatty) prompt_Printf(arg->prompt, "open, %s carrier\n", Online(modem) ? "with" : "no"); else diff --git a/usr.sbin/ppp/ppp/physical.c b/usr.sbin/ppp/ppp/physical.c index 9cf0b29d9cd..683f7943e27 100644 --- a/usr.sbin/ppp/ppp/physical.c +++ b/usr.sbin/ppp/ppp/physical.c @@ -16,7 +16,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: physical.c,v 1.1 1998/08/31 00:22:25 brian Exp $ + * $Id: physical.c,v 1.2 1999/01/10 02:23:22 brian Exp $ * */ @@ -53,11 +53,6 @@ physical_GetFD(struct physical *phys) { return phys->fd; } -int -physical_IsATTY(struct physical *phys) { - return isatty(phys->fd); -} - int physical_IsSync(struct physical *phys) { return phys->cfg.speed == 0; @@ -185,7 +180,7 @@ physical_IsSet(struct descriptor *d, const fd_set *fdset) void physical_Login(struct physical *phys, const char *name) { - if (phys->type == PHYS_DIRECT && physical_IsATTY(phys)) { + if (phys->type == PHYS_DIRECT && phys->isatty) { if (phys->Utmp) log_Printf(LogERROR, "Oops, already logged in on %s\n", phys->name.base); else { diff --git a/usr.sbin/ppp/ppp/physical.h b/usr.sbin/ppp/ppp/physical.h index 0081963ad42..89cb39581fd 100644 --- a/usr.sbin/ppp/ppp/physical.h +++ b/usr.sbin/ppp/ppp/physical.h @@ -16,7 +16,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: physical.h,v 1.1 1998/08/31 00:22:25 brian Exp $ + * $Id: physical.h,v 1.2 1999/01/10 02:23:22 brian Exp $ * */ @@ -30,11 +30,7 @@ struct physical { struct hdlc hdlc; /* Our hdlc state */ int fd; /* File descriptor for this device */ int mbits; /* Current DCD status */ - unsigned dev_is_modem : 1; /* Is the device an actual modem? - Faked for sync devices, though... - (Possibly this should be - dev_is_not_tcp?) XXX-ML */ - + unsigned isatty : 1; struct mbuf *out; /* mbuf that suffered a short write */ int connect_count; struct datalink *dl; /* my owner */ @@ -72,7 +68,6 @@ struct physical { ((d)->type == PHYSICAL_DESCRIPTOR ? field2phys(d, desc) : NULL) extern int physical_GetFD(struct physical *); -extern int physical_IsATTY(struct physical *); extern int physical_IsSync(struct physical *); extern const char *physical_GetDevice(struct physical *); extern void physical_SetDeviceList(struct physical *, int, const char *const *); -- cgit v1.2.3