aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/init
diff options
context:
space:
mode:
authorOphestra Umiker <cat@ophivana.moe>2024-10-17 02:38:24 +0900
committerOphestra Umiker <cat@ophivana.moe>2024-10-17 02:38:24 +0900
commit5401882ed0f4e6ca28d1312bc29b90bb4d64a04f (patch)
tree9676776845e97ada4435fead1fa9abd9f2bc0440 /internal/init
parentdd78728fb3f35a3f858b281a64c0803089a86f66 (diff)
init: post initial process death exit timeout
Wait for 5 seconds before printing a message and exiting after picking up the initial process's wait status. This also kills any lingering processes.This behaviour is helpful for applications launched without a terminal attached. Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'internal/init')
-rw-r--r--internal/init/main.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/internal/init/main.go b/internal/init/main.go
index 074b5051..e79618b2 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)
}
}
}