From mboxrd@z Thu Jan 1 00:00:00 1970 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes Resent-Date: Wed, 3 Feb 1999 06:24:53 -0500 (EST) Message-Id: <9902031108.AA50042@ibmth.df.unipi.it> To: zsh-workers@math.gatech.edu Subject: PATCH: 3.1.5-pws-6: ttys revisited In-Reply-To: ""Bart Schaefer""'s message of "Sat, 30 Jan 1999 10:04:51 NFT." <990130100451.ZM12586@candle.brasslantern.com> Date: Wed, 03 Feb 1999 12:08:57 +0100 From: Peter Stephenson Resent-Message-ID: <"_Kzpi.0.pT.583ks"@math> Resent-From: zsh-workers@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Resent-Sender: zsh-workers-request@math.gatech.edu X-Mailing-List: 5205 ioctl for non-exclusive tty use: "Bart Schaefer" wrote: > (For PWS et al.) Even if it should always be done, I think it'd be a good > idea to move this code down the point where an attempt to open /dev/tty > might be made anyway, so that it needn't be opened and closed more than > once. That seems to be sensible. This patch will do the whole thing pretty cheaply: only the `if (SHTTY == -1 && errno == EBUSY)' is usually executed. --- Src/init.c.nxcl2 Mon Feb 1 15:28:02 1999 +++ Src/init.c Wed Feb 3 12:01:41 1999 @@ -301,22 +301,19 @@ /* Make sure the tty is opened read/write. */ if (isatty(0)) { + zsfree(ttystrname); + if ((ttystrname = ztrdup(ttyname(0)))) { + SHTTY = movefd(open(ttystrname, O_RDWR | O_NOCTTY)); #ifdef TIOCNXCL - /* - * See if the terminal claims to be busy. If so, and fd 0 - * is a terminal, try and set non-exclusive use for that. - * This is something to do with Solaris over-cleverness. - */ - int tmpfd; - if ((tmpfd = open("/dev/tty", O_RDWR | O_NOCTTY)) < 0) { - if (errno == EBUSY) + /* + * See if the terminal claims to be busy. If so, and fd 0 + * is a terminal, try and set non-exclusive use for that. + * This is something to do with Solaris over-cleverness. + */ + if (SHTTY == -1 && errno == EBUSY) ioctl(0, TIOCNXCL, 0); - } else - close(tmpfd); #endif - zsfree(ttystrname); - if ((ttystrname = ztrdup(ttyname(0)))) - SHTTY = movefd(open(ttystrname, O_RDWR | O_NOCTTY)); + } /* * xterm, rxvt and probably all terminal emulators except * dtterm on Solaris 2.6 & 7 have a bug. Applications are -- Peter Stephenson Tel: +39 050 844536 WWW: http://www.ifh.de/~pws/ Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy