[hacknews] three bug fixes for shell

david@utzoo.UUCP (David Trueman) (04/13/84)

We are now running a new version of the shell (sh(1)) with three bugs fixed.
When a pipeline is created by the shell, only the last process is explicitly
waited for.  In the V7 shell the function that waited for that last process
to complete also waited for any other children, while in the system 5 shell
the function returned as soon as the last process finished.  This is reasonable
under most circumstances, as the last process is normally the last to complete,
but under some circumstances earlier processes in the pipeline were left 
"stranded" and potentially stealing input from the terminal.  The system 5
shell now behaves the same as the V7 shell in this respect.

The second bug was found in both shells.  When the shell executes another shell
file, rather than exec'ing another instance of the shell, it just forks and 
does a longjump(3).  This is a valuable optimization, but it means that great
care must be taken to ensure that the environment (in the most general sense)
of the "new" shell is identical to what it would have been if it were a "fresh"
copy.  The bug was that the exported status of environment variables was not
being cleared before the longjump.  The effect of this was that a shell file
might see the wrong values for environment variables.  The following example 
illustrates the problem:

	% cat fileA
	TERM=xxx	# note no export -- value should not be known outside
	fileB
	% cat fileB
	echo "TERM is $TERM should be vt100!"
	% TERM=vt100 ; export TERM
	% file A
	TERM is xxx should be vt100!
	%
		
Both of these bugs were discovered in trying to get a very simple shell script
to work.  The script was /bin/npr .

The third was arguably not a bug, but certainly an annoyance:  under some 
circumstances involving a pipeline where one of the later processes died
prematurely, the shell generated a spurious newline.  This behaviour was 
exhibited by both the V7 and system 5 shells.
-- 
				David Trueman @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!david