From ae2628e57a25e86568fe00281f07cecfa103cde4 Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Mon, 18 Nov 2024 13:33:46 +0900 Subject: cmd/fshim/ipc: install signal handler on shim start Getting killed at this point will result in inconsistent state. Signed-off-by: Ophestra Umiker --- cmd/fshim/ipc/shim/shim.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'cmd') diff --git a/cmd/fshim/ipc/shim/shim.go b/cmd/fshim/ipc/shim/shim.go index a03b6003..db4a9b09 100644 --- a/cmd/fshim/ipc/shim/shim.go +++ b/cmd/fshim/ipc/shim/shim.go @@ -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 { -- cgit v1.3.1