diff options
author | Tobias Bosch <tbosch@google.com> | 2019-08-22 09:35:10 -0700 |
---|---|---|
committer | Tobias Bosch <tbosch@google.com> | 2019-08-22 18:54:41 +0000 |
commit | eff107c774ae5f49e3531d20aaf4cb46a705b8d9 (patch) | |
tree | aa0ad735099b3db49e70eeedf27110f31f99362b /compiler_wrapper/env.go | |
parent | 3e482f294ed90e3569274bad10aba4000fc6376c (diff) | |
download | toolchain-utils-eff107c774ae5f49e3531d20aaf4cb46a705b8d9.tar.gz |
Always use /proc/self/cwd to get current directory.
We are not using os.getwd() as this sometimes uses the value of the PWD
env variable. This has the following problems:
- if PWD=/proc/self/cwd, os.getwd() will return "/proc/self/cwd",
and we need to read the link to get the actual wd. However, we can't always
do this as we are calculating
the path to clang, and following a symlinked cwd first would make
this calculation invalid.
- the old python wrapper doesn't respect the PWD env variable either, so if we
did we would fail the comparison to the old wrapper.
BUG=chromium:773875
TEST=emerge-lakitu app-emulation/docker
Change-Id: Ifc49ab4eed66121f6710b38cf8457173fb559204
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1764624
Tested-by: Tobias Bosch <tbosch@google.com>
Reviewed-by: George Burgess <gbiv@chromium.org>
Diffstat (limited to 'compiler_wrapper/env.go')
-rw-r--r-- | compiler_wrapper/env.go | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/compiler_wrapper/env.go b/compiler_wrapper/env.go index cde8b8fa..399ba354 100644 --- a/compiler_wrapper/env.go +++ b/compiler_wrapper/env.go @@ -29,19 +29,19 @@ type processEnv struct { } func newProcessEnv() (env, error) { - wd, err := os.Getwd() + // Note: We are not using os.getwd() as this sometimes uses the value of the PWD + // env variable. This has the following problems: + // - if PWD=/proc/self/cwd, os.getwd() will return "/proc/self/cwd", + // and we need to read the link to get the actual wd. However, we can't always + // do this as we are calculating + // the path to clang, and following a symlinked cwd first would make + // this calculation invalid. + // - the old python wrapper doesn't respect the PWD env variable either, so if we + // did we would fail the comparison to the old wrapper. + wd, err := os.Readlink("/proc/self/cwd") if err != nil { return nil, wrapErrorwithSourceLocf(err, "failed to read working directory") } - // Special case for linux when setting PWD=/proc/self/cwd. - // Don't do this for regular symlinked directories, as we are calculating - // the path to clang, and following a symlinked cwd first would make - // this calculation invalid. - if wd == "/proc/self/cwd" { - if wd, err = os.Readlink(wd); err != nil { - return nil, wrapErrorwithSourceLocf(err, "failed to read wd symlink %s", wd) - } - } return &processEnv{wd: wd}, nil } |