diff --git a/utils_linux.go b/utils_linux.go index a37b1c3d..ce50db14 100644 --- a/utils_linux.go +++ b/utils_linux.go @@ -3,7 +3,6 @@ package main import ( - "errors" "fmt" "net" "os" @@ -20,6 +19,7 @@ import ( "github.com/opencontainers/runtime-spec/specs-go" "github.com/coreos/go-systemd/activation" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/urfave/cli" "golang.org/x/sys/unix" @@ -281,6 +281,11 @@ func (r *runner) run(config *specs.Process) (int, error) { } baseFd := 3 + len(process.ExtraFiles) for i := baseFd; i < baseFd+r.preserveFDs; i++ { + _, err := os.Stat(fmt.Sprintf("/proc/self/fd/%d", i)) + if err != nil { + r.destroy() + return -1, errors.Wrapf(err, "please check that preserved-fd %d (of %d) is present", i-baseFd, r.preserveFDs) + } process.ExtraFiles = append(process.ExtraFiles, os.NewFile(uintptr(i), "PreserveFD:"+strconv.Itoa(i))) } rootuid, err := r.container.Config().HostRootUID()