Skip to content

Commit f05d358

Browse files
committed
Receive SIGINT only in RunInteractiveShell
Temporarily reset SIGINT signal handlers and receive SIGINT in RunInteractiveShell. Do not try to kill the process in micro when signal is received.
1 parent 26ae1b9 commit f05d358

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

internal/shell/shell.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
shellquote "github.com/kballard/go-shellquote"
1313
"github.com/zyedidia/micro/v2/internal/screen"
14+
"github.com/zyedidia/micro/v2/internal/util"
1415
)
1516

1617
// ExecCommand executes a command using exec
@@ -95,15 +96,11 @@ func RunInteractiveShell(input string, wait bool, getOutput bool) (string, error
9596
cmd.Stderr = os.Stderr
9697

9798
// This is a trap for Ctrl-C so that it doesn't kill micro
98-
// Instead we trap Ctrl-C to kill the program we're running
99+
// micro is killed if the signal is ignored only on Windows, so it is
100+
// received
99101
c := make(chan os.Signal, 1)
102+
signal.Reset(os.Interrupt)
100103
signal.Notify(c, os.Interrupt)
101-
go func() {
102-
for range c {
103-
cmd.Process.Kill()
104-
}
105-
}()
106-
107104
cmd.Start()
108105
err = cmd.Wait()
109106

@@ -117,6 +114,9 @@ func RunInteractiveShell(input string, wait bool, getOutput bool) (string, error
117114
// Start the screen back up
118115
screen.TempStart(screenb)
119116

117+
signal.Notify(util.Sigterm, os.Interrupt)
118+
signal.Stop(c)
119+
120120
return output, err
121121
}
122122

0 commit comments

Comments
 (0)