rootlessport: drop Pdeathsig in favor of Kill

there is a race condition where the child process is immediately
killed:

[pid 2576752] arch_prctl(0x3001 /* ARCH_??? */, 0x7ffdf612f170) = -1 EINVAL (Invalid argument)
[pid 2576752] access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
[pid 2576752] --- SIGTERM {si_signo=SIGTERM, si_code=SI_USER, si_pid=2576742, si_uid=0} ---
[pid 2576752] +++ killed by SIGTERM +++

this happens because the parent process here really means the "parent
thread".

Since there is no way of running it on the main thread,
let's skip this functionality altogether and use kill(2).

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano
2020-02-12 18:39:30 +01:00
parent 2550ded989
commit 5b69e7f2ef

View File

@ -149,9 +149,6 @@ func parent() error {
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
@ -163,6 +160,12 @@ 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: outer: