summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1999-01-10 01:26:30 +0000
committerbrian <brian@FreeBSD.org>1999-01-10 01:26:30 +0000
commit541b200a907df9730d6c52f272bc2eb5385c41fe (patch)
tree05376906d358406080e4668bf48135700a58b1e8
parent3905f929a7f97b0ef4744b343438c8aa71eadaf2 (diff)
downloadFreeBSD-src-541b200a907df9730d6c52f272bc2eb5385c41fe.zip
FreeBSD-src-541b200a907df9730d6c52f272bc2eb5385c41fe.tar.gz
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.
-rw-r--r--usr.sbin/ppp/modem.c25
-rw-r--r--usr.sbin/ppp/physical.c9
-rw-r--r--usr.sbin/ppp/physical.h9
3 files changed, 17 insertions, 26 deletions
diff --git a/usr.sbin/ppp/modem.c b/usr.sbin/ppp/modem.c
index 3c89492..6ffb565 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.98 1998/08/09 15:34:11 brian Exp $
+ * $Id: modem.c,v 1.99 1998/08/26 18:07:56 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/physical.c b/usr.sbin/ppp/physical.c
index 680f487..875c459 100644
--- a/usr.sbin/ppp/physical.c
+++ b/usr.sbin/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.5 1998/08/07 18:42:50 brian Exp $
+ * $Id: physical.c,v 1.6 1998/08/25 17:48:43 brian Exp $
*
*/
@@ -54,11 +54,6 @@ physical_GetFD(struct physical *phys) {
}
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/physical.h b/usr.sbin/ppp/physical.h
index 2803248..bfd1c74 100644
--- a/usr.sbin/ppp/physical.h
+++ b/usr.sbin/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.3 1998/05/29 18:33:10 brian Exp $
+ * $Id: physical.h,v 1.4 1998/08/25 17:48:43 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 *);
OpenPOWER on IntegriCloud