diff options
| -rw-r--r-- | src/exec.c | 23 | ||||
| -rw-r--r-- | src/exec.h | 1 | ||||
| -rw-r--r-- | src/main.c | 7 |
3 files changed, 26 insertions, 5 deletions
@@ -511,6 +511,18 @@ void unwind_restore(const unwind *u) { /* ---- processes ------------------------------------------------------- */ /** + * @brief Temporary experiment: bit mask of fork-path steps to skip. + */ +int perf_ablate(void) { + static int bits = -1; + if (bits < 0) { + const char *s = getenv("ZASH_FORK_ABLATE"); + bits = s ? atoi(s) : 0; + } + return bits; +} + +/** * @brief fork() a copy of the shell. * * The child is a subshell: it forgets the parent's jobs and traps, and @@ -520,7 +532,8 @@ void unwind_restore(const unwind *u) { * raises an error. */ pid_t fork_shell(void) { - flush_all(); + if (!(perf_ablate() & 4)) + flush_all(); (void)shell_pid(); /* fix $$ before the pid changes */ pid_t pid = fork(); if (pid < 0) @@ -530,8 +543,10 @@ pid_t fork_shell(void) { stat_spawns = stat_forks = 0; if (job_launching) job_child_setup(); /* while SIGTTOU is still ignored */ - jobs_forget(); - trap_reset_child(); + if (!(perf_ablate() & 1)) + jobs_forget(); + if (!(perf_ablate() & 2)) + trap_reset_child(); } else { stat_forks++; if (job_launching) @@ -544,6 +559,8 @@ pid_t fork_shell(void) { * @brief Run a command as the whole remaining life of this (forked) process. */ [[noreturn]] static void child_eval(node *n) { + if (perf_ablate() & 8) + _exit(0); jmploc jl; if (setjmp(jl.buf) == 0) { exc_handler = &jl; @@ -109,6 +109,7 @@ enum { }; void find_command(const char *name, cmdinfo *ci, unsigned flags); +int perf_ablate(void); void func_define(const char *name, node *body, arena *owner); bool func_unset(const char *name); void func_each(void (*fn)(const char *name, void *arg), void *arg); @@ -280,7 +280,9 @@ void exit_shell(int status) { exiting = true; exitstatus = status; jmploc jl; - if (setjmp(jl.buf) == 0) { + if (perf_ablate() & 16) { + /* experiment: skip the EXIT trap */ + } else if (setjmp(jl.buf) == 0) { exc_handler = &jl; trap_run_exit(); } else if (exc_code == EXC_EXIT) { @@ -295,7 +297,8 @@ void exit_shell(int status) { if (!in_subshell && var_get("ZASH_PROCSTAT")) out_printf(&out2, "zash: spawns=%ld forks=%ld\n", stat_spawns, stat_forks); - flush_all(); + if (!(perf_ablate() & 32)) + flush_all(); _exit(code); } |
