1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00
cde/src/cmd/ksh93/bltins
Martijn Dekker 6f0e008cf7 Fix unsetting special vars in subshells (re: efa31503, 8b7f8f9b)
This fixes (or at least works around) a bug that caused special
variables such as PATH, LANG, LC_ALL, LINENO, etc. to lose their
effect after being unset in a subshell.

For example:
(unset PATH; PATH=/dev/null; ls); : wrongly ran 'ls'
(unset LC_ALL; LC_ALL=badlocale); : failed to print a diagnostic

This is yet another problem with non-forking/virtual subshells. If
you forced the subshell to fork (one way of doing this is using the
'ulimit' builtin, e.g. ulimit -t unlimited) before unsetting the
special variable, the problem vanished.

I've tried to localise the problem. I suspect the sh_assignok()
function, which is called from unall(), is to blame. This function
is supposed to make a copy of a variable node in the virtual
subshell's variable tree. Apparently, it fails to copy the
associated permanent discipline function settings (stored in the
np->nvfun->disc pointer) that gave these variables their special
effect, and which survive unset. However, my attempts to fix that
have been unsuccessful. If anyone can figure out a fix, please send
a patch/pull request!
Data point: This bug existed in 93u 2011-02-08, but did not yet
exist in M-1993-12-28-s+. So it is a regression.

Meanwhile, pending a proper fix, this commit adds a safe
workaround: it forces a non-forked subshell to fork before
unsetting such a special variable.

src/cmd/ksh93/bltins/typeset.c: unall():
- If we're in a non-forked, non-${ ...; } subshell, then before
  unsetting any variable, check for variables with internal
  trap/discipline functions, and call sh_subfork() if any are
  found. To avoid crashing, this must be done before calling
  sh_pushcontext(), so we need to loop through the args separately.

src/cmd/ksh93/tests/variables.sh:
- Remove the 'ulimit' that forced the fork; we do this in C now.

(cherry picked from commit 21b1a67156582e3cbd36936f4af908bb45211a4b)
2020-06-12 01:45:16 +02:00
..
alarm.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
cd_pwd.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
cflow.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
enum.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
getopts.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
hist.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
misc.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
mkservice.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
print.c Fix BUG_PUTIOERR: Check for and report I/O error in output builtins 2020-06-12 01:45:13 +02:00
read.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
regress.c Fix 47 typos in user-facing help and error messages 2020-06-12 01:45:12 +02:00
sleep.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
test.c Fix 'test'/'[' exit status >1 on error in arithmetic expression 2020-06-12 01:45:15 +02:00
trap.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
typeset.c Fix unsetting special vars in subshells (re: efa31503, 8b7f8f9b) 2020-06-12 01:45:16 +02:00
ulimit.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
umask.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
whence.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00