-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reproducer 1: ksh -c '( TMOUT=0 ); TMOUT=1; read v; print $?' Actual behaviour: waits for input indefinitely. Expected behaviour: one second delay, then output of exit status 1. Analysis: The value of TMOUT is initialised as a pointer into the static scope struct, sh.st (see init.c line 1918). This struct is saved and restored for virtual subshells and ksh functions (so the effect of TMOUT is always local to a ksh function). However, an assignment in a virtual subshell changes the value pointer to a newly allocated value node, so even when the value is restored at the end of the subshell, assigning to it will no longer modify sh.st.tmout. Reproducer 2: ksh -c 'TMOUT=1; { sleep 5; print; } | read a; print $?' Actual behaviour: one second delay, then output of exit status 1. Expected behaviour: since 'read' is reading from a pipe, TMOUT should be ignored, so the reproducer should take 5 seconds and print exit status 0. The manual page has always stated that TMOUT applies to the 'read' command "if a line is not entered within the prescribed number of seconds while reading from a terminal." The Bolsky & Korn book is silent on the matter. While 'read' in ksh has always timed out according to TMOUT even when reading from a pipe, the documentation has also always specified that it only times out when reading from a terminal. The behaviour described in the documentation makes a lot more sense, because an unexpected TMOUT value inherited from the environment may easily break scripts that use 'read' to read from slow commands via a pipe. (This in fact happened, as per @sckendall2's report). It is also possible that there are some scripts that depend on the current behaviour, but my estimation is that fixing this will solve more problems than it will cause. src/cmd/ksh93/sh/subshell.c: sh_assignok(): - When cloning a node for the subshell, check if the address of its value pointer is within the sh.st struct. If so, copy the value pointer to the cloned node, preserving the special meaning of the variable. (Note that the sh.st struct is integreally saved and restored for virtual subshells by sh_subshell(), so this change does not introduce a subshell leak.) src/cmd/ksh93/bltins/read.c: b_read(): - Only honour $TMOUT (sh.st.tmout) if standard input (0) is on a terminal (tty_check(0)==1). This fixes reproducer 2. src/cmd/ksh93/sh.1: - Fix documentation: unsetting '_' does not actually remove the special meaning of $_. Thanks to @sckendall2 for noticing. src/cmd/ksh93/edit/edit.c: tty_check(): - Minor tweak. We should only set e_savefd to -1 before calling tty_get(), to force it to call tcgetattr(3). If we return without calling tty_get(), keep the saved fd. (re: 53f4bc6) Thanks to @sckendall2 for the reports. Resolves: #782 Resolves: #783
- Loading branch information
Showing
7 changed files
with
49 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters