summaryrefslogtreecommitdiffhomepage
path: root/src/exec.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/exec.c')
-rw-r--r--src/exec.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/exec.c b/src/exec.c
index c0267a8..1967182 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -1226,11 +1226,11 @@ static int run_pure(simple_cmd *sc, output *o) {
* @brief Can a subshell run without a process of its own?
*
* Its body has to be one command whose name is written literally, that
- * name has to be a builtin which only writes output, and neither the
- * subshell nor the command may redirect or assign. Then nothing the
- * parent can see can change. A `fork()` copies the address space on
- * z/OS, 4.7 ms against 0.3 ms for a `spawn()`, and ksh88 does not pay it
- * for `( : )` either.
+ * name has to be a builtin which only writes output or changes directory
+ * state that can be restored, and neither the subshell nor the command may
+ * redirect or assign. Then nothing the parent can see can change. A
+ * `fork()` copies the address space on z/OS, 4.7 ms against 0.3 ms for a
+ * `spawn()`, and ksh88 does not pay it for `( : )` either.
*/
static bool subshell_in_process(const node *n) {
const node *b = n->u.body;
@@ -1239,7 +1239,7 @@ static bool subshell_in_process(const node *n) {
return false;
cmdinfo ci;
find_command(b->u.simple.args->plain, &ci, 0);
- return ci.kind == C_BUILTIN && (ci.bi->flags & BI_PURE);
+ return ci.kind == C_BUILTIN && (ci.bi->flags & (BI_PURE | BI_CD));
}
/* ---- pipelines ------------------------------------------------------- */
@@ -1843,6 +1843,13 @@ static int eval_subshell(node *n, unsigned flags) {
scope_pop();
return status;
}
+ if (ok && (sc.cmd.bi->flags & BI_CD)) {
+ int status;
+ if (builtin_cd_isolated(sc.argc, sc.argv, &status)) {
+ scope_pop();
+ return status;
+ }
+ }
scope_pop();
if (!ok)
return exitstatus;