From f05d3582b3f22b24596408375aa8639d6d9e0776 Mon Sep 17 00:00:00 2001 From: niten94 <127052329+niten94@users.noreply.github.com> Date: Mon, 17 Jun 2024 19:07:10 +0800 Subject: [PATCH] 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. --- internal/shell/shell.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/shell/shell.go b/internal/shell/shell.go index c38e6e88..5bf5973f 100644 --- a/internal/shell/shell.go +++ b/internal/shell/shell.go @@ -11,6 +11,7 @@ import ( shellquote "github.com/kballard/go-shellquote" "github.com/zyedidia/micro/v2/internal/screen" + "github.com/zyedidia/micro/v2/internal/util" ) // ExecCommand executes a command using exec @@ -95,15 +96,11 @@ func RunInteractiveShell(input string, wait bool, getOutput bool) (string, error cmd.Stderr = os.Stderr // This is a trap for Ctrl-C so that it doesn't kill micro - // Instead we trap Ctrl-C to kill the program we're running + // micro is killed if the signal is ignored only on Windows, so it is + // received c := make(chan os.Signal, 1) + signal.Reset(os.Interrupt) signal.Notify(c, os.Interrupt) - go func() { - for range c { - cmd.Process.Kill() - } - }() - cmd.Start() err = cmd.Wait() @@ -117,6 +114,9 @@ func RunInteractiveShell(input string, wait bool, getOutput bool) (string, error // Start the screen back up screen.TempStart(screenb) + signal.Notify(util.Sigterm, os.Interrupt) + signal.Stop(c) + return output, err }