aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/sandbox
diff options
context:
space:
mode:
authorGravatar philwo <philwo@google.com>2018-04-25 06:16:05 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-25 06:17:40 -0700
commitf032268f2d789ef734cd7e29ed23600abb1ddc04 (patch)
tree1acb0b39b177bb35bc18e29cd4ee32f8f122e563 /src/main/java/com/google/devtools/build/lib/sandbox
parent9b3eb9743641c031f429cbc504646d44bd3919a9 (diff)
sandbox: Generate actually unique sandbox paths.
Turns out the "unique" id returned by SpawnExecutionContext is only unique within one SpawnRunner, but not across multiple SpawnRunner classes. We have to prefix the generated path with the name of the current strategy in order to not run into conflicts when a build happens to use multiple different sandbox strategies. RELNOTES: None. PiperOrigin-RevId: 194230475
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/sandbox')
-rw-r--r--src/main/java/com/google/devtools/build/lib/sandbox/DarwinSandboxedSpawnRunner.java8
-rw-r--r--src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedSpawnRunner.java8
-rw-r--r--src/main/java/com/google/devtools/build/lib/sandbox/ProcessWrapperSandboxedSpawnRunner.java8
3 files changed, 18 insertions, 6 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/DarwinSandboxedSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/sandbox/DarwinSandboxedSpawnRunner.java
index 86631443bf..e1e4deb53c 100644
--- a/src/main/java/com/google/devtools/build/lib/sandbox/DarwinSandboxedSpawnRunner.java
+++ b/src/main/java/com/google/devtools/build/lib/sandbox/DarwinSandboxedSpawnRunner.java
@@ -195,8 +195,12 @@ final class DarwinSandboxedSpawnRunner extends AbstractSandboxSpawnRunner {
@Override
protected SpawnResult actuallyExec(Spawn spawn, SpawnExecutionContext context)
throws IOException, InterruptedException {
- // Each invocation of "exec" gets its own sandbox.
- Path sandboxPath = sandboxBase.getRelative(Integer.toString(context.getId()));
+ // Each invocation of "exec" gets its own sandbox base.
+ // Note that the value returned by context.getId() is only unique inside one given SpawnRunner,
+ // so we have to prefix our name to turn it into a globally unique value.
+ Path sandboxPath =
+ sandboxBase.getRelative(getName()).getRelative(Integer.toString(context.getId()));
+ sandboxPath.getParentDirectory().createDirectory();
sandboxPath.createDirectory();
// b/64689608: The execroot of the sandboxed process must end with the workspace name, just like
diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedSpawnRunner.java
index 888f9abab2..a19605b0b9 100644
--- a/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedSpawnRunner.java
+++ b/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedSpawnRunner.java
@@ -119,8 +119,12 @@ final class LinuxSandboxedSpawnRunner extends AbstractSandboxSpawnRunner {
@Override
protected SpawnResult actuallyExec(Spawn spawn, SpawnExecutionContext context)
throws IOException, ExecException, InterruptedException {
- // Each invocation of "exec" gets its own sandbox base, execroot and temporary directory.
- Path sandboxPath = sandboxBase.getRelative(Integer.toString(context.getId()));
+ // Each invocation of "exec" gets its own sandbox base.
+ // Note that the value returned by context.getId() is only unique inside one given SpawnRunner,
+ // so we have to prefix our name to turn it into a globally unique value.
+ Path sandboxPath =
+ sandboxBase.getRelative(getName()).getRelative(Integer.toString(context.getId()));
+ sandboxPath.getParentDirectory().createDirectory();
sandboxPath.createDirectory();
// b/64689608: The execroot of the sandboxed process must end with the workspace name, just like
diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/ProcessWrapperSandboxedSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/sandbox/ProcessWrapperSandboxedSpawnRunner.java
index b3865a73a5..629ec0c574 100644
--- a/src/main/java/com/google/devtools/build/lib/sandbox/ProcessWrapperSandboxedSpawnRunner.java
+++ b/src/main/java/com/google/devtools/build/lib/sandbox/ProcessWrapperSandboxedSpawnRunner.java
@@ -65,8 +65,12 @@ final class ProcessWrapperSandboxedSpawnRunner extends AbstractSandboxSpawnRunne
@Override
protected SpawnResult actuallyExec(Spawn spawn, SpawnExecutionContext context)
throws ExecException, IOException, InterruptedException {
- // Each invocation of "exec" gets its own sandbox.
- Path sandboxPath = sandboxBase.getRelative(Integer.toString(context.getId()));
+ // Each invocation of "exec" gets its own sandbox base.
+ // Note that the value returned by context.getId() is only unique inside one given SpawnRunner,
+ // so we have to prefix our name to turn it into a globally unique value.
+ Path sandboxPath =
+ sandboxBase.getRelative(getName()).getRelative(Integer.toString(context.getId()));
+ sandboxPath.getParentDirectory().createDirectory();
sandboxPath.createDirectory();
// b/64689608: The execroot of the sandboxed process must end with the workspace name, just like