diff --git a/internal/init/main.go b/internal/init/main.go index 074b505..e79618b 100644 --- a/internal/init/main.go +++ b/internal/init/main.go @@ -11,10 +11,16 @@ import ( "path" "strconv" "syscall" + "time" "git.ophivana.moe/cat/fortify/internal/verbose" ) +const ( + // time to wait for linger processes after death initial process + residualProcessTimeout = 5 * time.Second +) + // everything beyond this point runs within pid namespace // proceed with caution! @@ -121,6 +127,8 @@ func doInit(fd uintptr) { close(done) }() + timeout := make(chan struct{}) + r := 2 for { select { @@ -138,8 +146,15 @@ func doInit(fd uintptr) { r = 255 } } + go func() { + time.Sleep(residualProcessTimeout) + close(timeout) + }() case <-done: os.Exit(r) + case <-timeout: + fmt.Println("fortify-init: timeout exceeded waiting for lingering processes") + os.Exit(r) } } }