feat: correct process sigint signal

This commit is contained in:
Evsyukov Denis 2024-02-08 19:23:50 +03:00
parent 9f533ac8b3
commit d3a2aa8fb0
No known key found for this signature in database

View file

@ -1,10 +1,12 @@
package main package main
import ( import (
"context"
"fmt" "fmt"
"log" "log"
"os" "os"
"os/exec" "os/exec"
"os/signal"
"syscall" "syscall"
"github.com/akamensky/argparse" "github.com/akamensky/argparse"
@ -46,6 +48,15 @@ func executablePath() string {
} }
func main() { func main() {
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGQUIT)
ctx, cancel := context.WithCancel(context.Background())
go func() {
<-s
cancel()
}()
exePath := executablePath() exePath := executablePath()
unveilOrPanic("/", "r") unveilOrPanic("/", "r")
unveilOrPanic(exePath, "x") unveilOrPanic(exePath, "x")
@ -138,5 +149,5 @@ func main() {
go spawner.SpawnRoutine(tnet) go spawner.SpawnRoutine(tnet)
} }
select {} // sleep eternally <-ctx.Done()
} }