-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
29 lines (26 loc) · 684 Bytes
/
main.go
File metadata and controls
29 lines (26 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package main
import (
"context"
"dis/cmd"
"dis/internal/procgroup"
"os"
"os/signal"
"syscall"
)
func main() {
// fang handles the first SIGINT/SIGTERM (cancels ctx).
// We install a second-signal handler as a backstop: if the user hits
// Ctrl+C again (or we receive another SIGTERM), forcefully kill all
// tracked child process groups before exiting.
go func() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
<-ch // first signal — handled by fang's NotifyContext
<-ch // second signal — user is impatient
procgroup.KillAll()
os.Exit(1)
}()
if err := cmd.Execute(context.Background()); err != nil {
os.Exit(1)
}
}