-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not call unset disc. upon subshell cleanup or running a script
Reproducer: $ ksh -c 'x.unset() { echo UNSET; }; (x=1); echo end' UNSET end The unset disciplien function is called while cleaning up the 'x' variable that was set in a subshell. Yet, if we cause the subshell to run in a separate process, that doesn't happen (note: 'ulimit' forces a virtual subshell to fork): $ ksh -c 'x.unset() { echo UNSET; }; (ulimit -c 0; x=1); echo end' end ...and that is the correct behaviour. `x` was never explicitly unset, it's just that the subshell terminated. So it's bogus that the unset discipline function got called. Virtual and real subshells should act identically (and, in this case, identically to main shells as well). Cleanup of subshell variables upon termination of a virtual subshell is done by nv_restore(). It sets a subshell_noscope flag to stop sh_assignok() from creating a virtual subshell scope during cleanup. This should stop assign() in nvdisc.c from executing an unset discipline as well. More bogosity (run the reproducer from this source tree): $ x.unset() { echo UNSET; } $ bin/package UNSET darwin.arm64-64 This happens when running a script without a #! path, which involves forking and then calling sh_reinit(), which unsets all the variables. Unset disciplines should be blocked there as well. src/cmd/ksh93/include/shell.h, src/cmd/ksh93/sh/subshell.c: - Add sh.nv_restore flag, to be set while nv_restore() is running. This now replaces subshell_noscope. src/cmd/ksh93/sh/nvdisc.c: assign(): - Refuse to run an unset discipline (i.e., assign() is called with val==NULL) if sh.nv_restore is set, or if the SH_INIT state flag is set (i.e. if sh_reinit() is running).
- Loading branch information
Showing
5 changed files
with
38 additions
and
8 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