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.
This commit is contained in:
parent
15c2c2f3da
commit
c0cdeb7c06
@ -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
|
||||
|
@ -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 $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -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 {
|
||||
|
@ -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 *);
|
||||
|
Loading…
Reference in New Issue
Block a user