rootless: fix regression when using exec on old containers

fallback to the previous behavior of joining only the user namespace,
when we cannot join the conmon userns+mount namespaces.

Closes: https://github.com/containers/libpod/issues/2673

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2019-03-25 23:15:24 +01:00
parent fcbca91dca
commit aacc5a8632
No known key found for this signature in database
GPG key ID: E4730F97F60286ED

View file

@ -112,14 +112,19 @@ func execCmd(c *cliconfig.ExecValues) error {
var ret int
data, err := ioutil.ReadFile(ctr.Config().ConmonPidFile)
if err != nil {
return errors.Wrapf(err, "cannot read conmon PID file %q", ctr.Config().ConmonPidFile)
if err == nil {
conmonPid, err := strconv.Atoi(string(data))
if err != nil {
return errors.Wrapf(err, "cannot parse PID %q", data)
}
became, ret, err = rootless.JoinDirectUserAndMountNS(uint(conmonPid))
} else {
pid, err := ctr.PID()
if err != nil {
return err
}
became, ret, err = rootless.JoinNS(uint(pid), c.PreserveFDs)
}
conmonPid, err := strconv.Atoi(string(data))
if err != nil {
return errors.Wrapf(err, "cannot parse PID %q", data)
}
became, ret, err = rootless.JoinDirectUserAndMountNS(uint(conmonPid))
if err != nil {
return err
}