mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
-o posix: disable '[ -t ]' == '[ -t 1 ]' hack
On ksh93, 'test -t' is equivalent to 'test -t 1' (and of course
"[ -t ]" is equivalent to "[ -t 1 ]").
This is purely for compatibility with ancient Bourne shell
breakage. No other shell supports this. ksh93 should probably keep
it for backwards compatibility, but it should definitely be
disabled in POSIX mode as it is a violation of the standard; 'test
-t' is an instance of 'test "$string"', which tests if the string
is empty, so it should test if the string '-t' is empty (quod non).
This also replaces the fix for 'test -t 1' in a command
substitution with a better one that avoids forking (re: cafe33f0
).
src/cmd/ksh93/sh/parse.c:
- qscan(): If the posix option is active, disable the parser-based
hack that converts a simple "[ -t ]" to "[ -t 1 ]".
src/cmd/ksh93/bltins/test.c:
- e3(): If the posix option is active, disable the part of the
compatibility hack that was used for compound expressions
that end in '-t', e.g. "[ -t 2 -o -t ]".
- test_unop(): Remove the forking fix for "[ -t 1 ]".
src/cmd/ksh93/edit/edit.c:
- tty_check(): This function is used by "[ -t 1 ]" and in other
contexts as well, so a fix here is more comprehensive. Forking
here would cause a segfault, but we don't actually need to. This
adds a fix that simply returns false if we're in a virtual
subshell that is also a command substitution. Since command
substitutions always fork upon redirecting standard output within
them (making them no longer virtual), it is safe to do this.
src/cmd/ksh93/tests/bracket.sh
- Add comprehensive regression tests for test/[/[[ -t variants in
command substitutions, in simple and compound expressions, with
and without redirecting stdout to /dev/tty within the comsub.
- Add tests verifying that -o posix disables the old hack.
- Tweak other tests, including one that globally disabled xtrace.
This commit is contained in:
parent
9077fcc3a4
commit
55f0f8ce52
6 changed files with 75 additions and 25 deletions
|
@ -162,6 +162,12 @@ int tty_check(int fd)
|
|||
{
|
||||
register Edit_t *ep = (Edit_t*)(shgd->ed_context);
|
||||
struct termios tty;
|
||||
/*
|
||||
* The tty_get check below does not work on 1 (stdout) in command substitutions. But comsubs fork upon redirecting 1,
|
||||
* and forking resets sh.subshell to 0, so we can safely return false when in a virtual subshell that is a comsub.
|
||||
*/
|
||||
if(fd==1 && sh.subshell && sh.comsub)
|
||||
return(0);
|
||||
ep->e_savefd = -1;
|
||||
return(tty_get(fd,&tty)==0);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue