diff options
author | Tobias Bosch <tbosch@google.com> | 2019-09-09 08:34:23 -0700 |
---|---|---|
committer | Tobias Bosch <tbosch@google.com> | 2019-09-09 20:43:02 +0000 |
commit | 478cfee03066d58ca3899753de95a58f35a96835 (patch) | |
tree | eb76f34d2787c55cb54d3d5aeb22b1871abbacb5 /compiler_wrapper | |
parent | 6270cccfcd886478a9c1b20acf9e8cd50a673a19 (diff) | |
download | toolchain-utils-478cfee03066d58ca3899753de95a58f35a96835.tar.gz |
Modify hostenv and use execv instead of execve.
This is needed so that the gentoo sandbox picks up
changes to the SANDBOX_WRITE env variable correctly,
which we update for ccache.
BUG=chromium:773875
TEST=emerge-kevin sci-libs/tensorflow
Change-Id: I6377c109f30071182b5af6948f320c7c53df4062
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1792228
Reviewed-by: George Burgess <gbiv@chromium.org>
Tested-by: Tobias Bosch <tbosch@google.com>
Diffstat (limited to 'compiler_wrapper')
-rw-r--r-- | compiler_wrapper/env.go | 15 | ||||
-rw-r--r-- | compiler_wrapper/libc_execv.go (renamed from compiler_wrapper/libc_execve.go) | 9 |
2 files changed, 17 insertions, 7 deletions
diff --git a/compiler_wrapper/env.go b/compiler_wrapper/env.go index 71e4c7ef..588441dd 100644 --- a/compiler_wrapper/env.go +++ b/compiler_wrapper/env.go @@ -9,6 +9,7 @@ import ( "fmt" "io" "os" + "os/exec" "strings" ) @@ -71,8 +72,18 @@ func (env *processEnv) stderr() io.Writer { } func (env *processEnv) exec(cmd *command) error { - execCmd := newExecCmd(env, cmd) - return libcExecve(execCmd.Path, execCmd.Args, execCmd.Env) + execCmd := exec.Command(cmd.Path, cmd.Args...) + // Note: We are not using execve and pass the new environment here + // as that sometimes doesn't work well with the gentoo sandbox to + // pick update changes to SANDBOX_WRITE env variable (needed for ccache). + // Instead, we are updating our own environment and call execv. + // This update of global state is ok as we won't execute anything else + // after the exec. + for _, update := range cmd.EnvUpdates { + parts := strings.Split(update, "=") + os.Setenv(parts[0], parts[1]) + } + return libcExecv(execCmd.Path, execCmd.Args) } func (env *processEnv) run(cmd *command, stdin io.Reader, stdout io.Writer, stderr io.Writer) error { diff --git a/compiler_wrapper/libc_execve.go b/compiler_wrapper/libc_execv.go index 53160695..19c40ef0 100644 --- a/compiler_wrapper/libc_execve.go +++ b/compiler_wrapper/libc_execv.go @@ -7,9 +7,8 @@ package main // #include <stdlib.h> // #include <unistd.h> // #include <errno.h> -// int libc_execve(const char *pathname, char *const argv[], -// char *const envp[]) { -// if (execve(pathname, argv, envp) != 0) { +// int libc_execv(const char *pathname, char *const argv[]) { +// if (execv(pathname, argv) != 0) { // return errno; // } // return 0; @@ -24,7 +23,7 @@ import ( // LD_PRELOAD to work properly (e.g. gentoo sandbox). // Note that this changes the go binary to be a dynamically linked one. // See crbug.com/1000863 for details. -func libcExecve(argv0 string, argv []string, envv []string) error { +func libcExecv(argv0 string, argv []string) error { freeList := []unsafe.Pointer{} defer func() { for _, ptr := range freeList { @@ -55,7 +54,7 @@ func libcExecve(argv0 string, argv []string, envv []string) error { return (**C.char)(cArray) } - if errno := C.libc_execve(goStrToC(argv0), goSliceToC(argv), goSliceToC(envv)); errno != 0 { + if errno := C.libc_execv(goStrToC(argv0), goSliceToC(argv)); errno != 0 { return newErrorwithSourceLocf("exec error: %d", errno) } |