From: Alan Cox Date: Thu, 21 May 2015 22:58:49 +0000 (+0100) Subject: tty: handle close better X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=ad59a7240df134177c574bda1ffe9f7794eb806c;p=FUZIX.git tty: handle close better --- diff --git a/Kernel/include/tty.h b/Kernel/include/tty.h index 1a87684d..47020180 100644 --- a/Kernel/include/tty.h +++ b/Kernel/include/tty.h @@ -151,10 +151,10 @@ struct termios { 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 diff --git a/Kernel/tty.c b/Kernel/tty.c index 5ee924f4..61e9ab7a 100644 --- a/Kernel/tty.c +++ b/Kernel/tty.c @@ -172,6 +172,10 @@ int tty_open(uint8_t minor, uint16_t flag) 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; @@ -187,18 +191,21 @@ int tty_open(uint8_t minor, uint16_t flag) 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); }