diff --git a/cmd/fshim/ipc/shim/shim.go b/cmd/fshim/ipc/shim/shim.go index a03b600..db4a9b0 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 { diff --git a/internal/app/start.go b/internal/app/start.go index 0b90583..c33d26f 100644 --- a/internal/app/start.go +++ b/internal/app/start.go @@ -179,7 +179,11 @@ func (a *app) Wait() (int, error) { // alternative exit path when kill was unsuccessful case err := <-a.shim.WaitFallback(): r = 255 - fmsg.Printf("cannot terminate shim on faulted setup: %v", err) + if err != nil { + fmsg.Printf("cannot terminate shim on faulted setup: %v", err) + } else { + fmsg.VPrintln("alternative exit path selected") + } } }