File tree 1 file changed +26
-1
lines changed
1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change 1
1
package cmd
2
2
3
3
import (
4
+ "context"
4
5
"fmt"
5
6
"io"
6
7
"io/ioutil"
7
8
"os"
8
9
"os/exec"
10
+ "os/signal"
9
11
"path"
10
12
"strings"
13
+ "syscall"
11
14
12
15
"github.com/fntlnz/mountinfo"
13
16
"github.com/spf13/cobra"
@@ -87,7 +90,29 @@ func (o *TraceRunnerOptions) Run() error {
87
90
}
88
91
}
89
92
90
- c := exec .Command (o .bpftraceBinaryPath , programPath )
93
+ fmt .Println ("if you have maps to print, send a SIGINT using Ctrl-C, if you want to interrupt the execution send SIGINT two times" )
94
+ ctx , cancel := context .WithCancel (context .Background ())
95
+ sigCh := make (chan os.Signal , 1 )
96
+
97
+ signal .Notify (sigCh , os .Signal (syscall .SIGINT ))
98
+
99
+ go func () {
100
+ killable := false
101
+ defer cancel ()
102
+ M:
103
+ select {
104
+ case <- ctx .Done ():
105
+ return
106
+ case <- sigCh :
107
+ if ! killable {
108
+ killable = true
109
+ goto M
110
+ }
111
+ return
112
+ }
113
+ }()
114
+
115
+ c := exec .CommandContext (ctx , o .bpftraceBinaryPath , programPath )
91
116
c .Stdout = os .Stdout
92
117
c .Stdin = os .Stdin
93
118
c .Stderr = os .Stderr
You can’t perform that action at this time.
0 commit comments