CVS commit: src/bin/sh
"Robert Elz" <[email protected]>
| Newsgroups | gmane.os.netbsd.devel.cvs |
|---|---|
| Message-ID | <[email protected]> |
Module Name: src Committed By: kre Date: Wed Jul 1 12:06:27 UTC 2026 Modified Files: src/bin/sh: eval.c jobs.c trap.c Log Message: /bin/sh fix trap/jobid builtins when run from grandchild The trap and jobid builtins are designed to allow T=$(trap) (etc) to see (output) the traps (or jobs for jobid) of parent shell (the one running the assignment) to be seen from inside a subshell (here the command substitution, which it usually would be). But all that should be reported are the traps (jobs) of the parent of that subshell, not recursively up the chain. That is ( T=$(trap) ) should usually be equivalent to T='' as inside a subshell environment all non-ignored traps are defined to be reset to their defaults For actual execution purposes, they were, but the loophole that allowed the trap command to see its parent's traps was so large, that it would have been able to see back to its distant ancestry (at least as far back until something had happened in that subshell to cause all of its ancestors traps to be forgotten .. setting any trap does that). Now if we enter a subshell, from an environment with no actual traps set, but which still has its parent's trap strings available for examination, those trap strings (in the grandchild) are immediately deleted, so now it sees only the traps it set itself, and any its immediate parent set. Much the same applies to the jobid (and jobs) builtins wrt the jobs table, though things were more broken there, and sometimes the data wasn't available when it should have been. All that is fixed now. Further, an irritation I knew of, but had never worked out how to easily fix, is now gone as well, it used to be that J=$(jobid %%) would only ever report about the command substitution itself (that being the "current job" for the purposes of %%). That makes no sense, and is useless, so now command substitutions (while they get a job table entry for the parent, so it can wait for them to finish) no longer become the current job (since there is no way to run (only) a command substitution in the background, the parent shell can never attempt to get information about a running cmdsub, so that %% used to be moved to the cmdsub, then moved back when it ended, was irrelevant to the parent. It made it needlessly weird for uses like $(jobid %%) or $(jobid %-) (etc) though, so cmdsubs are now never promoted to be %% (they're rather tenuous in the jobs table anyway). While these changes to alter the way the shell works, slightly, if anything actually notices (apart from the new sh tests) I'd be very surprised. No pullups planned. To generate a diff of this commit: cvs rdiff -u -r1.199 -r1.200 src/bin/sh/eval.c cvs rdiff -u -r1.126 -r1.127 src/bin/sh/jobs.c cvs rdiff -u -r1.62 -r1.63 src/bin/sh/trap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.