zsh-workers
 help / color / mirror / code / Atom feed
* Revised tty-opening patch
@ 1995-09-19 11:34 P.Stephenson
  0 siblings, 0 replies; only message in thread
From: P.Stephenson @ 1995-09-19 11:34 UTC (permalink / raw)
  To: Zsh hackers list

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@swansea.ac.uk>  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.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1995-09-19 11:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-09-19 11:34 Revised tty-opening patch P.Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).