From 794cd66df87b34217fdf2f64d23afa0a7453bd0c Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 7 Oct 2021 10:25:55 -0700 Subject: [PATCH] libct/system: Exec: wrap the error If the container binary to be run is removed in between runc create and runc start, the latter spits the following error: > can't exec user process: no such file or directory This is a bit confusing since we don't see what file is missing. Wrap the unix.Exec error into os.PathError, like in many other cases, to provide some context. Remove the error wrapping from (*linuxStandardInit).Init as it is now redundant. With this patch, the error is now: > exec /bin/false: no such file or directory Reported-by: Daniel J Walsh Signed-off-by: Kir Kolyshkin --- libcontainer/standard_init_linux.go | 2 +- libcontainer/system/linux.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libcontainer/standard_init_linux.go b/libcontainer/standard_init_linux.go index 6dfea9998..cd722c7e7 100644 --- a/libcontainer/standard_init_linux.go +++ b/libcontainer/standard_init_linux.go @@ -239,7 +239,7 @@ func (l *linuxStandardInit) Init() error { } if err := system.Exec(name, l.config.Args[0:], os.Environ()); err != nil { - return fmt.Errorf("can't exec user process: %w", err) + return err } return nil } diff --git a/libcontainer/system/linux.go b/libcontainer/system/linux.go index bb612daa6..6701b5ea2 100644 --- a/libcontainer/system/linux.go +++ b/libcontainer/system/linux.go @@ -4,6 +4,7 @@ package system import ( + "os" "os/exec" "unsafe" @@ -43,7 +44,7 @@ func Exec(cmd string, args []string, env []string) error { for { err := unix.Exec(cmd, args, env) if err != unix.EINTR { //nolint:errorlint // unix errors are bare - return err + return &os.PathError{Op: "exec", Path: cmd, Err: err} } } }