Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Revised tty-opening patch
- X-seq: zsh-workers 391
- From: P.Stephenson@xxxxxxxxxxxxx
- To: zsh-workers@xxxxxxxxxxxxxxx (Zsh hackers list)
- Subject: Revised tty-opening patch
- Date: Tue, 19 Sep 95 12:34:29 +0100
Here's an alternative (and simpler) patch for making sure the TTY is
opened read/write: as suggested by Zoltan, and I believe one other
poster, it opens /dev/tty if it can't get the tty attached to fd 0
r/w. This is a simple change since it tried to open /dev/tty anyway
if fd 0 wasn't attached to a tty. I've put in some extra code to make
sure SHTTY is -1 when init_io() is called if and only if there's no tty,
and to make sure there's no fd leak if init_io() is repeatedly called.
The result is that if you use a root-owned terminal and su to a zsh
user, the terminal will be /dev/tty rather than the actual device
name. I could try harder to dup(0) and see if that's writeable first
if anybody really cares about the name, but this is the simplest
solution.
*** Src/init.c.tty Tue Sep 19 05:54:06 1995
--- Src/init.c Tue Sep 19 12:27:52 1995
***************
*** 56,61 ****
--- 56,62 ----
setflags();
parseargs(argv);
+ SHTTY = -1;
init_io();
setupvals();
init_signals();
***************
*** 331,341 ****
fclose(shout);
shout = 0;
}
/* Make sure the tty is opened read/write. */
if (isatty(0))
SHTTY = movefd(open(ttyname(0), O_RDWR));
! else
SHTTY = movefd(open("/dev/tty", O_RDWR));
if (SHTTY != -1) {
--- 332,346 ----
fclose(shout);
shout = 0;
}
+ if (SHTTY != -1) {
+ close(SHTTY);
+ SHTTY = -1;
+ }
/* Make sure the tty is opened read/write. */
if (isatty(0))
SHTTY = movefd(open(ttyname(0), O_RDWR));
! if (SHTTY == -1)
SHTTY = movefd(open("/dev/tty", O_RDWR));
if (SHTTY != -1) {
--
Peter Stephenson <P.Stephenson@xxxxxxxxxxxxx> Tel: +44 1792 205678 extn. 4461
WWW: http://python.swan.ac.uk/~pypeters/ Fax: +44 1792 295324
Department of Physics, University of Wales, Swansea,
Singleton Park, Swansea, SA2 8PP, U.K.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author