mirror of https://github.com/containers/podman.git
libpod: if slirp4netns fails, return its output
read the slirp4netns stderr and propagate it in the error when the process fails. Replace: https://github.com/containers/libpod/pull/4338 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
parent
ac73fd3fe5
commit
795460f7b0
|
@ -5,6 +5,7 @@ package libpod
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -131,7 +132,7 @@ func checkSlirpFlags(path string) (bool, bool, bool, error) {
|
||||||
cmd := exec.Command(path, "--help")
|
cmd := exec.Command(path, "--help")
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, false, false, err
|
return false, false, false, errors.Wrapf(err, "slirp4netns %q", out)
|
||||||
}
|
}
|
||||||
return strings.Contains(string(out), "--disable-host-loopback"), strings.Contains(string(out), "--mtu"), strings.Contains(string(out), "--enable-sandbox"), nil
|
return strings.Contains(string(out), "--disable-host-loopback"), strings.Contains(string(out), "--mtu"), strings.Contains(string(out), "--enable-sandbox"), nil
|
||||||
}
|
}
|
||||||
|
@ -158,6 +159,7 @@ func (r *Runtime) setupRootlessNetNS(ctr *Container) (err error) {
|
||||||
|
|
||||||
havePortMapping := len(ctr.Config().PortMappings) > 0
|
havePortMapping := len(ctr.Config().PortMappings) > 0
|
||||||
apiSocket := filepath.Join(ctr.runtime.config.TmpDir, fmt.Sprintf("%s.net", ctr.config.ID))
|
apiSocket := filepath.Join(ctr.runtime.config.TmpDir, fmt.Sprintf("%s.net", ctr.config.ID))
|
||||||
|
logPath := filepath.Join(ctr.runtime.config.TmpDir, fmt.Sprintf("slirp4netns-%s.log", ctr.config.ID))
|
||||||
|
|
||||||
cmdArgs := []string{}
|
cmdArgs := []string{}
|
||||||
if havePortMapping {
|
if havePortMapping {
|
||||||
|
@ -165,7 +167,7 @@ func (r *Runtime) setupRootlessNetNS(ctr *Container) (err error) {
|
||||||
}
|
}
|
||||||
dhp, mtu, sandbox, err := checkSlirpFlags(path)
|
dhp, mtu, sandbox, err := checkSlirpFlags(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "error checking slirp4netns binary %s", path)
|
return errors.Wrapf(err, "error checking slirp4netns binary %s: %q", path, err)
|
||||||
}
|
}
|
||||||
if dhp {
|
if dhp {
|
||||||
cmdArgs = append(cmdArgs, "--disable-host-loopback")
|
cmdArgs = append(cmdArgs, "--disable-host-loopback")
|
||||||
|
@ -210,6 +212,18 @@ func (r *Runtime) setupRootlessNetNS(ctr *Container) (err error) {
|
||||||
// Leak one end of the pipe in slirp4netns, the other will be sent to conmon
|
// Leak one end of the pipe in slirp4netns, the other will be sent to conmon
|
||||||
cmd.ExtraFiles = append(cmd.ExtraFiles, ctr.rootlessSlirpSyncR, syncW)
|
cmd.ExtraFiles = append(cmd.ExtraFiles, ctr.rootlessSlirpSyncR, syncW)
|
||||||
|
|
||||||
|
logFile, err := os.Create(logPath)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "failed to open slirp4netns log file %s", logPath)
|
||||||
|
}
|
||||||
|
defer logFile.Close()
|
||||||
|
// Unlink immediately the file so we won't need to worry about cleaning it up later.
|
||||||
|
// It is still accessible through the open fd logFile.
|
||||||
|
if err := os.Remove(logPath); err != nil {
|
||||||
|
return errors.Wrapf(err, "delete file %s", logPath)
|
||||||
|
}
|
||||||
|
cmd.Stdout = logFile
|
||||||
|
cmd.Stderr = logFile
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
return errors.Wrapf(err, "failed to start slirp4netns process")
|
return errors.Wrapf(err, "failed to start slirp4netns process")
|
||||||
}
|
}
|
||||||
|
@ -238,7 +252,15 @@ func (r *Runtime) setupRootlessNetNS(ctr *Container) (err error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if status.Exited() {
|
if status.Exited() {
|
||||||
return errors.New("slirp4netns failed")
|
// Seek at the beginning of the file and read all its content
|
||||||
|
if _, err := logFile.Seek(0, 0); err != nil {
|
||||||
|
logrus.Errorf("could not seek log file: %q", err)
|
||||||
|
}
|
||||||
|
logContent, err := ioutil.ReadAll(logFile)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "slirp4netns failed")
|
||||||
|
}
|
||||||
|
return errors.Errorf("slirp4netns failed: %q", logContent)
|
||||||
}
|
}
|
||||||
if status.Signaled() {
|
if status.Signaled() {
|
||||||
return errors.New("slirp4netns killed by signal")
|
return errors.New("slirp4netns killed by signal")
|
||||||
|
|
Loading…
Reference in New Issue