summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers+gitlab@digital-scurf.org>2020-06-06 13:34:42 +0000
committerDaniel Silverstone <dsilvers+gitlab@digital-scurf.org>2020-06-06 13:34:42 +0000
commit40f3c837310456aaca480a817eb0b6d5e6577b90 (patch)
tree4709cbb055e35e50cfbf7a31ee180db2b1bfaeeb
parent7061fe6957774c80c8deedd2df80416aa7128bd7 (diff)
parent83db7a29fd4432f28adcd01039ba468716cacc10 (diff)
downloadsubplot-40f3c837310456aaca480a817eb0b6d5e6577b90.tar.gz
Merge branch 'env' into 'master'
feat: set up a minimal environment in the code templates Closes #60 See merge request larswirzenius/subplot!48
-rw-r--r--templates/bash/template.sh11
-rw-r--r--templates/python/template.py13
2 files changed, 24 insertions, 0 deletions
diff --git a/templates/bash/template.sh b/templates/bash/template.sh
index 286e56f..89958d4 100644
--- a/templates/bash/template.sh
+++ b/templates/bash/template.sh
@@ -176,6 +176,8 @@ scenario_{{ loop.index }}() {
scendir="$(mktemp -d -p "$_datadir")"
cd "$scendir"
+ export HOME="$scendir"
+
ctx_new
cleanups[0]=''
steps[0]=''
@@ -227,6 +229,15 @@ scenario_{{ loop.index }}() {
{% endfor %}
#############################################################################
+# Make the environment minimal.
+
+unset $(env | sed 's/=.*//')
+export PATH=/bin:/usr/bin
+export SHELL=/bin/sh
+export HOME=/ # Will be set to datadir for each scenario.
+
+
+#############################################################################
# Run the scenarios.
if [ "$#" = 0 ]
diff --git a/templates/python/template.py b/templates/python/template.py
index a1fa3ee..4ceeb51 100644
--- a/templates/python/template.py
+++ b/templates/python/template.py
@@ -156,6 +156,7 @@ class Scenario:
scendir = tempfile.mkdtemp(dir=_datadir)
os.chdir(scendir)
+ os.environ['HOME'] = scendir
ctx = Context()
done = []
@@ -216,6 +217,17 @@ def parse_command_line():
return p.parse_args()
+def setup_minimal_environment():
+ minimal = {
+ 'PATH': '/bin:/usr/bin',
+ 'SHELL': '/bin/sh',
+ 'HOME': '/', # will be set to datadir for each scenario
+ }
+
+ os.environ.clear()
+ os.environ.update(minimal)
+
+
def setup_logging(args):
if args.log:
fmt = "%(asctime)s %(levelname)s %(message)s"
@@ -243,6 +255,7 @@ def save_directory(dirname, tarname):
def main():
args = parse_command_line()
+ setup_minimal_environment()
setup_logging(args)
logging.info("Test program starts")