From da59e8ce3fc5a35b3d22dd971ff96f498f655a98 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 26 Sep 2021 10:17:00 -0700 Subject: New variable: *child-env*. This specifies the environment to be used for executing programs. * stream.c (open_subprocess, run): Check *child-env* variable and if other than t, then install the environment before execvp. In the spawn-based version of run, we save and restore the environment around the spawn call, if *child-env* is in effect. * sysif.c (child_env_s): New symbol variable. (exec_wrap): If *child-env* is other than t, then save the environment in a list, and install the specified environment before calling execvp. If that function returns, restore the environbment. * sysif.h (child_env_s): Declared. (child_env): New macro. * tests/018/process.tl: New tests. * txr.1: Documented. * stdlib/doc-syms.tl: Updated. --- tests/018/process.tl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests') diff --git a/tests/018/process.tl b/tests/018/process.tl index 07ecfb64..a1970738 100644 --- a/tests/018/process.tl +++ b/tests/018/process.tl @@ -25,3 +25,17 @@ (mtest (fcmd (let ((*stdout* *stdnull*)) (sh "echo foo"))) "" (fcmd (let ((*stderr* *stdout*)) (sh "echo foo 1>&2"))) "foo\n"))) + +(mtest + (let ((*child-env* '("a=b"))) + (get-lines (open-process "/usr/bin/env" "r"))) + ("a=b") + (let ((*child-env* nil)) + (get-lines (open-process "/usr/bin/env" "r"))) + nil) + +(test + (fcmd + (let ((*child-env* '("a=b"))) + (run "/usr/bin/env"))) + "a=b\n") -- cgit v1.2.3