virtualenv_wrapper: fix recursive invocation
The wrapper works by checking for an env var to see if it's inside
of the virtualenv already. If it's not, it sets the var, and then
re-execs itself inside the virtualenv.
If a program using this wrapper attempts to execute another program
that uses this wrapper, that invocation fails because it thinks it's
inside of the virtualenv already. This is because we bleed the env
var into children processes.
Since the env var was only there as a side-channel to allow for self
re-execing w/out hitting an infinite loop, remove the env var from
the active environment once the wrapper finishes wrapping.
This comes up when moving cbuildbot to the virtualenv wrapper -- if
it tries to bootstrap another cbuildbot invocation like CQ patching
or the workspace logic, it all falls down.
BUG=chromium:997354
TEST=CQ passes
Change-Id: I8a929a5f4c158ed824923745ca243725e905fa9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2150228
Reviewed-by: Chris McDonald <cjmcdonald@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/scripts/virtualenv_wrapper.py b/scripts/virtualenv_wrapper.py
index 5d52ecf..995eca9 100755
--- a/scripts/virtualenv_wrapper.py
+++ b/scripts/virtualenv_wrapper.py
@@ -31,6 +31,9 @@
def main():
if _IsInsideVenv(os.environ):
+ # Don't bleed the marker into children processes that might use the wrapper
+ # themselves to run inside of the virtualenv.
+ os.environ.pop(_VENV_MARKER)
wrapper3.DoMain()
else:
venvdir = _CreateVenv()