mirror of
https://github.com/containers/podman.git
synced 2025-05-22 01:27:07 +08:00
Merge pull request #3173 from giuseppe/use-wait-for-file
libpod: prefer WaitForFile to polling
This commit is contained in:
@ -25,7 +25,6 @@ import (
|
|||||||
opentracing "github.com/opentracing/opentracing-go"
|
opentracing "github.com/opentracing/opentracing-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
kwait "k8s.io/apimachinery/pkg/util/wait"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -146,20 +145,10 @@ func (c *Container) exitFilePath() string {
|
|||||||
func (c *Container) waitForExitFileAndSync() error {
|
func (c *Container) waitForExitFileAndSync() error {
|
||||||
exitFile := c.exitFilePath()
|
exitFile := c.exitFilePath()
|
||||||
|
|
||||||
err := kwait.ExponentialBackoff(
|
chWait := make(chan error)
|
||||||
kwait.Backoff{
|
defer close(chWait)
|
||||||
Duration: 500 * time.Millisecond,
|
|
||||||
Factor: 1.2,
|
_, err := WaitForFile(exitFile, chWait, time.Second*5)
|
||||||
Steps: 6,
|
|
||||||
},
|
|
||||||
func() (bool, error) {
|
|
||||||
_, err := os.Stat(exitFile)
|
|
||||||
if err != nil {
|
|
||||||
// wait longer
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
return true, nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Exit file did not appear
|
// Exit file did not appear
|
||||||
// Reset our state
|
// Reset our state
|
||||||
|
@ -17,7 +17,6 @@ import (
|
|||||||
"github.com/opencontainers/selinux/go-selinux/label"
|
"github.com/opencontainers/selinux/go-selinux/label"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
kwait "k8s.io/apimachinery/pkg/util/wait"
|
|
||||||
|
|
||||||
// TODO import these functions into libpod and remove the import
|
// TODO import these functions into libpod and remove the import
|
||||||
// Trying to keep libpod from depending on CRI-O code
|
// Trying to keep libpod from depending on CRI-O code
|
||||||
@ -261,21 +260,13 @@ func (r *OCIRuntime) updateContainerStatus(ctr *Container, useRuntime bool) erro
|
|||||||
// If we were, it should already be in the database
|
// If we were, it should already be in the database
|
||||||
if ctr.state.State == ContainerStateStopped && oldState != ContainerStateStopped {
|
if ctr.state.State == ContainerStateStopped && oldState != ContainerStateStopped {
|
||||||
var fi os.FileInfo
|
var fi os.FileInfo
|
||||||
err = kwait.ExponentialBackoff(
|
chWait := make(chan error)
|
||||||
kwait.Backoff{
|
defer close(chWait)
|
||||||
Duration: 500 * time.Millisecond,
|
|
||||||
Factor: 1.2,
|
_, err := WaitForFile(exitFile, chWait, time.Second*5)
|
||||||
Steps: 6,
|
if err == nil {
|
||||||
},
|
fi, err = os.Stat(exitFile)
|
||||||
func() (bool, error) {
|
}
|
||||||
var err error
|
|
||||||
fi, err = os.Stat(exitFile)
|
|
||||||
if err != nil {
|
|
||||||
// wait longer
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
return true, nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctr.state.ExitCode = -1
|
ctr.state.ExitCode = -1
|
||||||
ctr.state.FinishedTime = time.Now()
|
ctr.state.FinishedTime = time.Now()
|
||||||
|
Reference in New Issue
Block a user