mirror of
https://github.com/containers/podman.git
synced 2025-06-21 09:28:09 +08:00
Merge pull request #5183 from giuseppe/rootlessport-avoid-hang
rootlessport: fix potential hang
This commit is contained in:
@ -122,6 +122,7 @@ func parent() error {
|
|||||||
logrus.WithError(driverErr).Warn("parent driver exited")
|
logrus.WithError(driverErr).Warn("parent driver exited")
|
||||||
}
|
}
|
||||||
errCh <- driverErr
|
errCh <- driverErr
|
||||||
|
close(errCh)
|
||||||
}()
|
}()
|
||||||
opaque := driver.OpaqueForChild()
|
opaque := driver.OpaqueForChild()
|
||||||
logrus.Infof("opaque=%+v", opaque)
|
logrus.Infof("opaque=%+v", opaque)
|
||||||
@ -142,15 +143,12 @@ func parent() error {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
// reexec the child process in the child netns
|
// reexec the child process in the child netns
|
||||||
cmd := exec.Command(fmt.Sprintf("/proc/%d/exe", os.Getpid()))
|
cmd := exec.Command("/proc/self/exe")
|
||||||
cmd.Args = []string{reexecChildKey}
|
cmd.Args = []string{reexecChildKey}
|
||||||
cmd.Stdin = childQuitR
|
cmd.Stdin = childQuitR
|
||||||
cmd.Stdout = &logrusWriter{prefix: "child"}
|
cmd.Stdout = &logrusWriter{prefix: "child"}
|
||||||
cmd.Stderr = cmd.Stdout
|
cmd.Stderr = cmd.Stdout
|
||||||
cmd.Env = append(os.Environ(), reexecChildEnvOpaque+"="+string(opaqueJSON))
|
cmd.Env = append(os.Environ(), reexecChildEnvOpaque+"="+string(opaqueJSON))
|
||||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
|
||||||
Pdeathsig: syscall.SIGTERM,
|
|
||||||
}
|
|
||||||
childNS, err := ns.GetNS(cfg.NetNSPath)
|
childNS, err := ns.GetNS(cfg.NetNSPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -162,14 +160,27 @@ func parent() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := syscall.Kill(cmd.Process.Pid, syscall.SIGTERM); err != nil {
|
||||||
|
logrus.WithError(err).Warn("kill child process")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
logrus.Info("waiting for initComplete")
|
logrus.Info("waiting for initComplete")
|
||||||
// wait for the child to connect to the parent
|
// wait for the child to connect to the parent
|
||||||
|
outer:
|
||||||
|
for {
|
||||||
select {
|
select {
|
||||||
case <-initComplete:
|
case <-initComplete:
|
||||||
logrus.Infof("initComplete is closed; parent and child established the communication channel")
|
logrus.Infof("initComplete is closed; parent and child established the communication channel")
|
||||||
|
break outer
|
||||||
case err := <-errCh:
|
case err := <-errCh:
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
logrus.Info("stopping parent driver")
|
logrus.Info("stopping parent driver")
|
||||||
quit <- struct{}{}
|
quit <- struct{}{}
|
||||||
|
Reference in New Issue
Block a user