cmd/fshim/ipc: install signal handler on shim start
test / test (push) Successful in 20s Details

Getting killed at this point will result in inconsistent state.

Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
Ophestra Umiker 2024-11-18 13:33:46 +09:00
parent c026a4b5dc
commit ae2628e57a
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
2 changed files with 16 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import (
"net"
"os"
"os/exec"
"os/signal"
"strings"
"sync"
"sync/atomic"
@ -128,6 +129,16 @@ func (s *Shim) Start() (*time.Time, error) {
}
defer func() { killShim() }()
// take alternative exit path on signal
sig := make(chan os.Signal, 2)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
go func() {
v := <-sig
fmsg.Printf("got %s after program start", v)
s.killFallback <- nil
signal.Ignore(syscall.SIGINT, syscall.SIGTERM)
}()
accept()
var conn *net.UnixConn
select {

View File

@ -179,7 +179,11 @@ func (a *app) Wait() (int, error) {
// alternative exit path when kill was unsuccessful
case err := <-a.shim.WaitFallback():
r = 255
if err != nil {
fmsg.Printf("cannot terminate shim on faulted setup: %v", err)
} else {
fmsg.VPrintln("alternative exit path selected")
}
}
}