Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 11 Nov 2010 17:02:10 -0800 (PST)
From:      "Ronald F.Guilmette" <rfg@tristatelogic.com>
To:        FreeBSD-gnats-submit@FreeBSD.org
Cc:        rfg@tristatelogic.com
Subject:   bin/152154: /bin/csh & /bin/tcsh improperly diddle termios flags
Message-ID:  <20101112010210.87641BDC46@segfault.tristatelogic.com>
Resent-Message-ID: <201011120110.oAC1A94V049336@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         152154
>Category:       bin
>Synopsis:       /bin/csh & /bin/tcsh improperly diddle termios flags
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Nov 12 01:10:09 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     Ronald F. Guilmette
>Release:        FreeBSD 7.0-RELEASE i386
>Organization:
Infinite Monkeys & Co.
>Environment:

System: FreeBSD segfault.tristatelogic.com 7.0-RELEASE FreeBSD 7.0-RELEASE #0: Tue Aug 5 02:38:40 PDT 2008 root@segfault.monkeys.com:/usr/src/sys/i386/compile/rfg20080805 i386

>Description:

Apparently, /bin/csh (aka /bin/tcsh) is diddling termios flags, in particular
the ECHO flag, for no apparently good reason and without ever even having been
asked to do so.  The result is that the /usr/bin/script program, when invoked
with the -k option, will log every input character the user types in TWICE,
but only if the user has SHELL set in the environment to either /bin/csh or
to /bin/tcsh.  This behavior does not seem to occur when and if SHELL is set
to /bin/sh.

>How-To-Repeat:

setenv SHELL /bin/tcsh
/usr/bin/script -k

Then just type something... anything... and then exit the shell and
then look at the typescript file to see the doubled characters.

I further traced this problem down by inserting the following changes into
/usr/bin/script.  These show what the termios flags look like before and
after the first call to select() within script.c, and thus they will show
how once tcsh is fired up (as a child process) by script, it changes the
termios flags on its pty, unsetting MANY of the bitflags, including ECHO.

Note that if you run /usr/bin/script with these changes installed, and do
so with SHELL set to /bin/sh then you will see that in that case, the
termios bit flags DO NOT get diddled by the child shell process, and that
the ECHO bitflag, in particular, does not get un-set, and thus, "script -k"
works properly in that case.

*** script.c.orig	2004-02-15 09:30:13.000000000 -0800
--- script.c	2010-11-11 16:41:15.000000000 -0800
***************
*** 92,95 ****
--- 92,96 ----
  	fd_set rfd;
  	int flushtime = 30;
+ 	int first_time = 1;
  
  	aflg = kflg = 0;
***************
*** 174,178 ****
--- 175,184 ----
  			tv.tv_usec = 0;
  		}
+ 		if (first_time & tcgetattr(master, &stt) >= 0)
+ 			fprintf (stderr, "Pre-select: 0x%08x\r\n", stt.c_lflag);
  		n = select(master + 1, &rfd, 0, 0, tvp);
+ 		if (first_time & tcgetattr(master, &stt) >= 0)
+ 			fprintf (stderr, "Post-select: 0x%08x\r\n", stt.c_lflag);
+ 		first_time = 0;
  		if (n < 0 && errno != EINTR)
  			break;

>Fix:

I have no idea how to fix this.  I tried to dredge into the tcsh source code,
but it is just too imposing for me right now.  So I'm sort-of hoping that
somebody more familiarity with tcsh than me will dredge into it and find the
problem.

P.S.  Strangely, when you run /usr/bin/script with SHELL set to /bin/tcsh
and when you then run a program from the tcsh command prompt, that program
will see a properly set group of termios bitflags, e.g. when and if it
calls tcgetattr().
>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20101112010210.87641BDC46>