mirror of
https://github.com/containers/podman.git
synced 2025-07-25 17:20:20 +08:00
Merge pull request #12126 from giuseppe/fix-race-warning-message
runtime: change PID existence check
This commit is contained in:
@ -545,9 +545,7 @@ func makeRuntime(ctx context.Context, runtime *Runtime) (retErr error) {
|
|||||||
if became {
|
if became {
|
||||||
// Check if the pause process was created. If it was created, then
|
// Check if the pause process was created. If it was created, then
|
||||||
// move it to its own systemd scope.
|
// move it to its own systemd scope.
|
||||||
if _, err = os.Stat(pausePid); err == nil {
|
utils.MovePauseProcessToScope(pausePid)
|
||||||
utils.MovePauseProcessToScope(pausePid)
|
|
||||||
}
|
|
||||||
os.Exit(ret)
|
os.Exit(ret)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/containers/podman/v3/libpod/define"
|
"github.com/containers/podman/v3/libpod/define"
|
||||||
"github.com/containers/podman/v3/pkg/cgroups"
|
"github.com/containers/podman/v3/pkg/cgroups"
|
||||||
"github.com/containers/storage/pkg/archive"
|
"github.com/containers/storage/pkg/archive"
|
||||||
|
"github.com/godbus/dbus/v5"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -177,13 +178,26 @@ func RunsOnSystemd() bool {
|
|||||||
func moveProcessToScope(pidPath, slice, scope string) error {
|
func moveProcessToScope(pidPath, slice, scope string) error {
|
||||||
data, err := ioutil.ReadFile(pidPath)
|
data, err := ioutil.ReadFile(pidPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// do not raise an error if the file doesn't exist
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return errors.Wrapf(err, "cannot read pid file %s", pidPath)
|
return errors.Wrapf(err, "cannot read pid file %s", pidPath)
|
||||||
}
|
}
|
||||||
pid, err := strconv.ParseUint(string(data), 10, 0)
|
pid, err := strconv.ParseUint(string(data), 10, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "cannot parse pid file %s", pidPath)
|
return errors.Wrapf(err, "cannot parse pid file %s", pidPath)
|
||||||
}
|
}
|
||||||
return RunUnderSystemdScope(int(pid), slice, scope)
|
err = RunUnderSystemdScope(int(pid), slice, scope)
|
||||||
|
|
||||||
|
// If the PID is not valid anymore, do not return an error.
|
||||||
|
if dbusErr, ok := err.(dbus.Error); ok {
|
||||||
|
if dbusErr.Name == "org.freedesktop.DBus.Error.UnixProcessIdUnknown" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// MovePauseProcessToScope moves the pause process used for rootless mode to keep the namespaces alive to
|
// MovePauseProcessToScope moves the pause process used for rootless mode to keep the namespaces alive to
|
||||||
|
Reference in New Issue
Block a user