From 0c4a45fa16183a56336cc73720c444b30281ac91 Mon Sep 17 00:00:00 2001 From: Lang Martin Date: Wed, 8 May 2019 10:01:20 -0400 Subject: [PATCH] executor_linux pass the command to lookupTaskBin to get path --- drivers/shared/executor/executor_linux.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/shared/executor/executor_linux.go b/drivers/shared/executor/executor_linux.go index 3c235206b..77304ec0b 100644 --- a/drivers/shared/executor/executor_linux.go +++ b/drivers/shared/executor/executor_linux.go @@ -143,7 +143,7 @@ func (l *LibcontainerExecutor) Launch(command *ExecCommand) (*ProcessState, erro l.container = container // Look up the binary path and make it executable - absPath, err := lookupTaskBin(command.TaskDir, command.Cmd) + absPath, err := lookupTaskBin(command) if err != nil { return nil, err @@ -774,7 +774,10 @@ func cmdMounts(mounts []*drivers.MountConfig) []*lconfigs.Mount { // lookupTaskBin finds the file `bin` in taskDir/local, taskDir in that order, then performs // a PATH search inside taskDir. It returns an absolute path. See also executor.lookupBin -func lookupTaskBin(taskDir string, bin string) (string, error) { +func lookupTaskBin(command *ExecCommand) (string, error) { + taskDir := command.TaskDir + bin := command.Cmd + // Check in the local directory localDir := filepath.Join(taskDir, allocdir.TaskLocal) local := filepath.Join(localDir, bin) @@ -788,10 +791,17 @@ func lookupTaskBin(taskDir string, bin string) (string, error) { return root, nil } + // Find the PATH + path := "/usr/local/bin:/usr/bin:/bin" + for _, e := range command.Env { + if strings.HasPrefix("PATH=", e) { + path = e[5:] + } + } + // Check the host PATH anchored inside the taskDir if !strings.Contains(bin, "/") { - envPath := os.Getenv("PATH") - for _, dir := range filepath.SplitList(envPath) { + for _, dir := range filepath.SplitList(path) { if dir == "" { // match unix shell behavior, empty path element == . dir = "."