summaryrefslogtreecommitdiffhomepage
path: root/src/exec.h
Commit message (Collapse)AuthorAgeFilesLines
* Merge main into perf/cd-inproc: one in-process `( cd dir )`, not twoSean Kurtz2 days1-16/+9
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | main gained an in-process `( cd dir )` of its own with the 2026-11-28 review merge (the uncommitted working tree the review was written against, committed as cb1688f), so this branch and main both replaced the fork for the same command, in two places. That copy has a defect this branch guards against: with readonly PWD; ( cd / ); echo after the readonly assignment raises out of the saved-cwd block and kills the whole shell - no `after` - where dash and bash both print it (dash rc=2, bash rc=1). `subshell_in_process()` here refuses to run the `cd` in-process unless PWD and OLDPWD are plain, and `builtin_cd_isolated()` holds its own exception handler, so the fork still happens in that case. Resolution: keep this branch's implementation and drop main's ad-hoc branch in eval_subshell() together with the curdir_invalidate() helper added for it, which had no other caller. The tests main brought with it (tests/zash/subshell-cd.sh, tests/proc/subshell-pure.sh) still pass. Verified on Linux (7.3.4-300.fc45.x86_64, 2026-11-28): make check 127 passed / 1 skipped / the known linux/i-dscomplete failure, make asan and make valgrind the same, make mvs-asan 127 passed, make zos-lint clean, the readonly-PWD case now matches dash. Not re-run on cbt.
| * fix(signal): install SIG_DFL with sigaction, not signal()Sean Kurtz3 days1-0/+1
| | | | | | | | | | | | | | | | | | Two places reset a signal to its default: main() for an inherited SIGCHLD (waitpid() fails with ECHILD when a parent left it ignored) and the pipeline child that writes a long builtin output and must die on SIGPIPE. Both went through signal(), which differs from sigaction() in restart and mask behaviour; they now share trap.c's set_handler() through a small trap_sig_default(), the function trap_reset() already uses.
| * fix(exec): run the ERR trap when the last command is exec'dSean Kurtz3 days1-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | `trap "echo ERR" ERR; /bin/false` printed nothing: the shell replaced itself with the failing program and was gone before the trap could run. The same shortcut made `trap ... ; (/bin/false)` silently skip it. trap_after_last() is true when the EXIT or the ERR trap is set, and both the exec shortcut in run_external() and the in-process subshell shortcut in eval_subshell() now use it instead of trap_has_exit(). tests/zash/errtrap-exec.sh covers the external command, a builtin, a subshell and the two traps together; the first and third lines fail without the change. ksh93 prints ERR for all four.
| * wip: vi external edit and dot-repeat, in-process cd subshell, perf testSean Kurtz3 days1-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The working tree the 2026-11-28 review was written against, committed unchanged so the review fixes can sit on top of it. - vi mode: `v` edits the line in $VISUAL, else $EDITOR (edit_external), and `.` repeats the last change, count and all. - `( cd dir )` runs in-process with the directory saved and restored, instead of forking, and its invalidation of the cached logical cwd. - tests/perf: a start-up cost guard; tests/run.sh runs that directory. - README: set +o pipetag for ASCII builds. - formal/zash-spec.txt regenerated as text. - .clang-tidy: two checks re-enabled (no findings after the change). - tests/scripts/webdocs: a `#` inside a fenced block is not a title.
| * feat: select, the ksh88 menu loopSean Kurtz3 days1-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | IBM's /bin/sh is of the KornShell line and `select` is part of what its scripts use, so the shell that replaces it has to have it. The menu goes to stderr as "number TAB word", then PS3 (default "#? "); the answer is read with the rules of `read REPLY`; a number in range picks that word, anything else leaves the variable empty and the body still runs, a blank line only prompts again, and end of input ends the loop. The node is the `for` node with a `menu` flag, since the two differ only in what the body sees. tests/zash/select.sh prints the same bytes under zash and under the CBT /bin/sh; the specification has the rule.
| * fix: the review findings, each with a regression testSean Kurtz3 days1-16/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Notes in notes/review-2026-11-27.md, one item per finding: 1. error unwinding read dead stack frames: the scope/redirection/input snapshot now lives in jmploc and is restored before the longjmp 2. `for` without `in` iterated over parameters that `set --` could free: the parameter block is reference-counted 3. `${4294967295}` and `${99999999999999999999}` indexed past the end: strtol, clamped to 1..$# 4. a trap stopped running after its own action raised: the re-entry flag is cleared before the action runs 5. `wait $pid` returned 127 once the job had been reaped 6. every external command failed with 127 when SIGCHLD was ignored at startup: dispositions are reset before the first child 7. a failed `exec` killed an interactive shell and skipped its EXIT trap: the shell returns 126/127, keeping the traps and restoring fds 0-9 8. `set -C` opened with O_TRUNC after a stat: O_EXCL, with the non-regular-file case worked around 9. a here-doc cut off by EOF used the delimiter as its body 10. `cd -- dir` failed and PWD came from the failed logical path 11. deep arithmetic recursion overflowed the stack: a depth check 12. the CSI type byte was converted twice on EBCDIC: guarded by ZASH_ASCII 13. a script that could not be read looked like an empty script: reported, with 2 at top level and 126/127 for the script; a directory is refused up front, because z/OS would otherwise read it as empty input Minors: `trap -p SIG`, `read -t` clamping and NaN, ksh `base#n` arithmetic, `${#@}`/`${#*}` as `$#`, `jobs` no longer mutating its table from a pipeline, the arena_grow contract, no pipe2 on macOS, and alias text copied into the input so redefining an alias while it is being read is safe.
* | perf: restore cwd after a lone ( cd dir ) in-processperf/cd-inprocSean Kurtz5 days1-1/+1
| | | | | | | | | | | | | | A subshell whose body is a single cd now runs in the parent shell with the directory, PWD, OLDPWD and curdir saved and restored, instead of forking. On z/OS a fork costs ~0.4 ms there; the cd itself costs ~5 us. A readonly, integer or dynamic PWD/OLDPWD keeps the forked path.
* | perf: run a lone ( cd dir ) without forkingSean Kurtz5 days1-0/+2
|/
* C23: constexpr internal linkage, naming and trailing commas; clangd at C23Sean Kurtz5 days1-3/+2
| | | | | | | | A constexpr at file scope has external linkage, so the CSI offsets and CSI_MAX_CALLS now say static. The naming check gets the C23 spellings wrap the check itself: typed constants keep the macro case, and a local static constexpr table keeps the variable case. .clangd says -std=c23, which it still did not, so the editor could not read constexpr at all.
* C23: compile as C23 and use its spellingSean Kurtz6 days1-3/+3
| | | | | | | | | | | | | | | | | | | | | | | The z/OS toolchain would not take C23 when this was first written; IBM Open XL C/C++ 2.2 does (clang 21.1, __STDC_VERSION__ 202311), and so does the clang on Linux. -std=c23 in the Makefile, and the standard attributes in place of the ones that were macros: _Noreturn -> [[noreturn]] (on declarations and definitions) _Static_assert -> static_assert _Alignas -> alignas NODISCARD -> [[nodiscard]] FALLTHROUGH -> [[fallthrough]] PRINTFLIKE and UNREACHABLE() stay macros: [[gnu::format]] and [[gnu::unreachable]] are vendor attributes, and the standard has no [[format]] or [[unreachable]] for a header-only project yet. Standard-library additions newer than the libc of either system (<stdbit.h>, <stdckdint.h>) are not used, so gcc -std=c2x still builds the tree warning-free. The suite, ASan/UBSan and the z/OS lint pass as before; linux/i-dscomplete remains the one local failure it was on main.
* Read startup files like the interactive shell they belong toSean Kurtz12 days1-0/+1
| | | | | | | | | | | A failing line in $ENV ended the shell: run_input() only installed its recovering handler for the main loop, so sh_error() found no handler and called exit_shell(). An interactive shell must not exit for a command that fails (POSIX 2.5.3), and a .kshrc shared with ksh is full of lines zash rejects. Startup files now run with RI_RECOVER, which recovers from an error without printing a prompt, and the rest of the file is still read.
* z/OS builtins: tag, alloc, freeSean Kurtz2026-11-151-0/+3
| | | | | | | | tag shows and sets file tags in chtag -p form without a process; alloc and free pass BPXWDYN requests. They exist only in z/OS builds (free must not hide procps elsewhere) and in make mvs-asan's build, which runs their usage-error test; tests/zos/builtins.sh covers the real work (unrun, VERIFY).
* Add [[ ]], make coverage, and fixes found by edge-case testsSean Kurtz2026-11-151-0/+3
| | | | | | | [[ ]] is parsed into a tree and evaluated without argv or lookup. Fixes: errexit inside a tested subshell, the ${x:?} message, arithmetic on variables holding expressions, printf %c of an empty argument, job text for arithmetic, and \n and \e prompt escapes.
* Add extensions, job control and the interactive layer; convert to C11Sean Kurtz2026-11-131-65/+152
| | | | | | | | | | | | | | | | | Language: $'...', aliases, function keyword, (( )) and let, typeset and integer, print, whence, setvar, ulimit, read -t, RANDOM, SECONDS, the ERR trap, trap -p, chdir, and more set -o names. Job control: a job table, process groups, terminal hand-over through the spawn layer, jobs/fg/bg, wait %n and kill %n. Interactive: prompt expansion, a built-in line editor with emacs and vi modes, completion, history with fc and HISTFILE, and libedit as a compile-time alternative (make EDIT=libedit LDLIBS=-ledit). The source is now C11 (was C23), uses typedef'd structs and enums, and has Doxygen comments throughout. Adds .clang-tidy, .clangd and a Doxyfile.
* zash: scripting core, test suite and benchmarksSean Kurtz2026-11-121-0/+164
A clean-slate POSIX shell for z/OS UNIX in the Almquist tradition, written in C23 for Clang (Linux) and IBM Open XL C/C++ (z/OS). - Parser, expansion, arithmetic, redirection, traps and builtins. - Spawn-first execution: fd plans instead of fork+dup2, in-shell pure builtins for pipelines and command substitution, $(a | b) without a subshell. - Flat .POSIX Makefile; asan, valgrind, bench, compdb and z/OS targets. - Tests: posix (dash-generated), zash, process accounting, linux, zos. Nothing has been compiled or run on z/OS yet.