From 0cd9a7e2f5eed7e798fab92eb90dae9ffc64d55a Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 19 Feb 2018 16:43:13 -0800 Subject: [PATCH] libcontainer/standard_init_linux: Move LookPath to post-wait This avoids a panic for containers that do not set Process. And even if Process was set, there is no reason to require the executable to be available *at create time* [1]. Subsequent activity could be scheduled to get a binary in place at the configured location before 'start' is called. [1]: https://github.com/opencontainers/runc/pull/827#discussion_r63464201 Signed-off-by: W. Trevor King --- libcontainer/standard_init_linux.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libcontainer/standard_init_linux.go b/libcontainer/standard_init_linux.go index 02ea753eda3..5b579235c25 100644 --- a/libcontainer/standard_init_linux.go +++ b/libcontainer/standard_init_linux.go @@ -3,6 +3,7 @@ package libcontainer import ( + "errors" "fmt" "os" "os/exec" @@ -152,12 +153,6 @@ func (l *linuxStandardInit) Init() error { if unix.Getppid() != l.parentPid { return unix.Kill(unix.Getpid(), unix.SIGKILL) } - // Check for the arg before waiting to make sure it exists and it is - // returned as a create time error. - name, err := exec.LookPath(l.config.Args[0]) - if err != nil { - return err - } // Close the pipe to signal that we have completed our init. l.pipe.Close() // Wait for the FIFO to be opened on the other side before exec-ing the @@ -186,6 +181,13 @@ func (l *linuxStandardInit) Init() error { return newSystemErrorWithCause(err, "init seccomp") } } + if len(l.config.Args) == 0 { + return errors.New("no process arguments configured") + } + name, err := exec.LookPath(l.config.Args[0]) + if err != nil { + return err + } if err := syscall.Exec(name, l.config.Args[0:], os.Environ()); err != nil { return newSystemErrorWithCause(err, "exec user process") }