summaryrefslogtreecommitdiffhomepage
path: root/runsc/specutils/specutils.go
diff options
context:
space:
mode:
authorKevin Krakauer <krakauer@google.com>2018-08-24 14:41:38 -0700
committerShentubot <shentubot@google.com>2018-08-24 14:42:40 -0700
commit02dfceab6d4c4a2a3342ef69be0265b7ab03e5d7 (patch)
tree31a84af980c995689395641e2a1cc2b5281e9e02 /runsc/specutils/specutils.go
parent7b0dfb0cdbdcb402c000d30399dbfd2eeebe1266 (diff)
runsc: Allow runsc to properly search the PATH for executable name.
Previously, runsc improperly attempted to find an executable in the container's PATH. We now search the PATH via the container's fsgofer rather than the host FS, eliminating the confusing differences between paths on the host and within a container. PiperOrigin-RevId: 210159488 Change-Id: I228174dbebc4c5356599036d6efaa59f28ff28d2
Diffstat (limited to 'runsc/specutils/specutils.go')
-rw-r--r--runsc/specutils/specutils.go25
1 files changed, 15 insertions, 10 deletions
diff --git a/runsc/specutils/specutils.go b/runsc/specutils/specutils.go
index 27441cbde..5fb53edb2 100644
--- a/runsc/specutils/specutils.go
+++ b/runsc/specutils/specutils.go
@@ -126,6 +126,8 @@ func ReadSpec(bundleDir string) (*specs.Spec, error) {
// GetExecutablePath returns the absolute path to the executable, relative to
// the root. It searches the environment PATH for the first file that exists
// with the given name.
+// TODO: Remove this in favor of finding executables via
+// boot.GetExecutablePathInternal.
func GetExecutablePath(exec, root string, env []string) (string, error) {
exec = filepath.Clean(exec)
@@ -134,18 +136,9 @@ func GetExecutablePath(exec, root string, env []string) (string, error) {
return exec, nil
}
- // Get the PATH from the environment.
- const prefix = "PATH="
- var path []string
- for _, e := range env {
- if strings.HasPrefix(e, prefix) {
- path = strings.Split(strings.TrimPrefix(e, prefix), ":")
- break
- }
- }
-
// Search the PATH for a file whose name matches the one we are looking
// for.
+ path := GetPath(env)
for _, p := range path {
abs := filepath.Join(root, p, exec)
// Do not follow symlink link because the target is in the container
@@ -161,6 +154,18 @@ func GetExecutablePath(exec, root string, env []string) (string, error) {
return exec, nil
}
+// GetPath returns the PATH as a slice of strings given the environemnt
+// variables.
+func GetPath(env []string) []string {
+ const prefix = "PATH="
+ for _, e := range env {
+ if strings.HasPrefix(e, prefix) {
+ return strings.Split(strings.TrimPrefix(e, prefix), ":")
+ }
+ }
+ return nil
+}
+
// Capabilities takes in spec and returns a TaskCapabilities corresponding to
// the spec.
func Capabilities(specCaps *specs.LinuxCapabilities) (*auth.TaskCapabilities, error) {