diff --git a/hst/config.go b/hst/config.go index 3aa71aa..f5689a4 100644 --- a/hst/config.go +++ b/hst/config.go @@ -11,6 +11,13 @@ const Tmp = "/.hakurei" var AbsTmp = container.MustAbs(Tmp) +const ( + // DefaultWaitDelay is used when WaitDelay has its zero value. + DefaultWaitDelay = 5 * time.Second + // MaxWaitDelay is used if WaitDelay exceeds its value. + MaxWaitDelay = 30 * time.Second +) + // Config is used to seal an app implementation. type ( Config struct { diff --git a/internal/app/finalise.go b/internal/app/finalise.go index f5ae398..ec2d0a9 100644 --- a/internal/app/finalise.go +++ b/internal/app/finalise.go @@ -186,13 +186,12 @@ func (k *outcome) finalise(ctx context.Context, msg container.Msg, id *state.ID, } // enforce bounds and default early - kp.waitDelay = shimWaitTimeout if s.Container.WaitDelay <= 0 { - kp.waitDelay += DefaultShimWaitDelay - } else if s.Container.WaitDelay > MaxShimWaitDelay { - kp.waitDelay += MaxShimWaitDelay + kp.waitDelay = hst.DefaultWaitDelay + } else if s.Container.WaitDelay > hst.MaxWaitDelay { + kp.waitDelay = hst.MaxWaitDelay } else { - kp.waitDelay += s.Container.WaitDelay + kp.waitDelay = s.Container.WaitDelay } if s.Container.MapRealUID { diff --git a/internal/app/process.go b/internal/app/process.go index 41fe4bd..63f424f 100644 --- a/internal/app/process.go +++ b/internal/app/process.go @@ -19,7 +19,7 @@ import ( "hakurei.app/system" ) -// duration to wait for shim to exit, after container WaitDelay has elapsed. +// Duration to wait for shim to exit on top of container WaitDelay. const shimWaitTimeout = 5 * time.Second // mainState holds persistent state bound to outcome.main. @@ -81,7 +81,7 @@ func (ms mainState) beforeExit(isFault bool) { waitDone := make(chan struct{}) // this ties waitDone to ctx with the additional compensated timeout duration - go func() { <-ms.k.ctx.Done(); time.Sleep(ms.waitDelay); close(waitDone) }() + go func() { <-ms.k.ctx.Done(); time.Sleep(ms.waitDelay + shimWaitTimeout); close(waitDone) }() select { case err := <-ms.cmdWait: diff --git a/internal/app/shim.go b/internal/app/shim.go index 417f793..de53b97 100644 --- a/internal/app/shim.go +++ b/internal/app/shim.go @@ -42,11 +42,6 @@ const ( ShimExitRequest = 254 // ShimExitOrphan is returned when the shim is orphaned before monitor delivers a signal. ShimExitOrphan = 3 - - // DefaultShimWaitDelay is used when WaitDelay has its zero value. - DefaultShimWaitDelay = 5 * time.Second - // MaxShimWaitDelay is used instead if WaitDelay exceeds its value. - MaxShimWaitDelay = 30 * time.Second ) // ShimMain is the main function of the shim process and runs as the unconstrained target user.