MCPcopy
hub / github.com/hashicorp/packer / handleTermInterrupt

Function handleTermInterrupt

command/signal.go:16–40  ·  view source on GitHub ↗
(ui packersdk.Ui)

Source from the content-addressed store, hash-verified

14)
15
16func handleTermInterrupt(ui packersdk.Ui) (context.Context, func()) {
17 ctx, cancelCtx := context.WithCancel(context.Background())
18 // Handle interrupts for this build
19 sigCh := make(chan os.Signal, 1)
20 signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
21 cleanup := func() {
22 cancelCtx()
23 signal.Stop(sigCh)
24 close(sigCh)
25 }
26 go func() {
27 select {
28 case sig := <-sigCh:
29 if sig == nil {
30 // context got cancelled and this closed chan probably
31 // triggered first
32 return
33 }
34 ui.Error(fmt.Sprintf("Cancelling build after receiving %s", sig))
35 cancelCtx()
36 case <-ctx.Done():
37 }
38 }()
39 return ctx, cleanup
40}

Callers 10

RunMethod · 0.85
RunMethod · 0.85
RunMethod · 0.85
RunMethod · 0.85
RunMethod · 0.85
RunMethod · 0.85
RunMethod · 0.85
RunMethod · 0.85
RunMethod · 0.85
RunMethod · 0.85

Calls 1

ErrorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…