the data indexed off a single register */
struct tty {
/* Put flag first: makes it cheaper when short of registers */
- uint8_t flag; /* Use uint8 pad - makes the whole struct
+ uint8_t flag; /* make the whole struct
24 byte - a nice number for CPUs with no
multiplier */
- uint8_t pad0;
+ uint8_t users;
#define TTYF_STOP 1
#define TTYF_DISCARD 2
#define TTYF_DEAD 4
udata.u_ptab->p_tty = minor;
t->pgrp = udata.u_ptab->p_pgrp;
}
+ if (t->users) {
+ t->users++;
+ return 0;
+ }
tty_setup(minor);
if ((t->termios.c_cflag & CLOCAL) || (flag & O_NDELAY))
return 0;
t->flag &= ~TTYF_DEAD;
return -1;
}
+ t->users++;
return 0;
}
int tty_close(uint8_t minor)
{
+ struct tty *t = &ttydata[minor];
+ if (--t->users)
+ return 0;
/* If we are closing the controlling tty, make note */
- if (minor == udata.u_ptab->p_tty) {
+ if (minor == udata.u_ptab->p_tty)
udata.u_ptab->p_tty = 0;
- ttydata[minor].pgrp = 0;
- }
+ t->pgrp = 0;
/* If we were hung up then the last opener has gone away */
- ttydata[minor].flag &= ~TTYF_DEAD;
+ t->flag &= ~TTYF_DEAD;
return (0);
}