add default polling interval to Container.Wait

Signed-off-by: Maximilian Hueter <maximilian.hueter@icloud.com>
This commit is contained in:
Maximilian Hueter
2024-10-30 19:54:49 +01:00
parent 2f6fca6edc
commit 314dece926

View File

@ -543,6 +543,8 @@ func (c *Container) Wait(ctx context.Context) (int32, error) {
// WaitForExit blocks until the container exits and returns its exit code. The // WaitForExit blocks until the container exits and returns its exit code. The
// argument is the interval at which checks the container's status. // argument is the interval at which checks the container's status.
// If the argument is less than or equal to 0 Nanoseconds a default interval is
// used.
func (c *Container) WaitForExit(ctx context.Context, pollInterval time.Duration) (int32, error) { func (c *Container) WaitForExit(ctx context.Context, pollInterval time.Duration) (int32, error) {
id := c.ID() id := c.ID()
if !c.valid { if !c.valid {
@ -593,6 +595,10 @@ func (c *Container) WaitForExit(ctx context.Context, pollInterval time.Duration)
defer unix.Close(conmonPidFd) defer unix.Close(conmonPidFd)
} }
if pollInterval <= 0 {
pollInterval = DefaultWaitInterval
}
// we cannot wait locked as we would hold the lock forever, so we unlock and then lock again // we cannot wait locked as we would hold the lock forever, so we unlock and then lock again
c.lock.Unlock() c.lock.Unlock()
err := waitForConmonExit(ctx, conmonPID, conmonPidFd, pollInterval) err := waitForConmonExit(ctx, conmonPID, conmonPidFd, pollInterval)