Merge pull request #2000 from lifubang/preserve-fds-error

fix preserve-fds flag may cause runc hang
This commit is contained in:
Michael Crosby 2019-03-04 10:45:17 -06:00 committed by GitHub
commit f416cac1fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -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()