From 454acd4f5c31262919417548158cfd4c96a7d359 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 8 May 2023 16:18:05 +0530 Subject: [PATCH] ssh kitten: Fix a regression in 0.28.0 that caused interrupt during setup to not be handled gracefully Fixes #6254 --- docs/changelog.rst | 2 ++ kittens/ssh/main.go | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 530f388cc..482a8d32e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -59,6 +59,8 @@ Detailed list of changes - edit-in-kitty: Fix running edit-in-kitty with elevated privileges to edit a restricted file not working (:disc:`6245`) +- ssh kitten: Fix a regression in 0.28.0 that caused interrupt during setup to not be handled gracefully (:iss:`6254`) + 0.28.1 [2023-04-21] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kittens/ssh/main.go b/kittens/ssh/main.go index 891c51bd0..80802b475 100644 --- a/kittens/ssh/main.go +++ b/kittens/ssh/main.go @@ -16,6 +16,7 @@ import ( "net/url" "os" "os/exec" + "os/signal" "os/user" "path" "path/filepath" @@ -669,6 +670,9 @@ func run_ssh(ssh_args, server_args, found_extra_args []string) (rc int, err erro if err != nil { return 1, err } + sigs := make(chan os.Signal, 8) + signal.Notify(sigs, unix.SIGINT, unix.SIGTERM) + if !cd.request_data { rq := fmt.Sprintf("id=%s:pwfile=%s:pw=%s", cd.replacements["REQUEST_ID"], cd.replacements["PASSWORD_FILENAME"], cd.replacements["DATA_PASSWORD"]) err := term.ApplyOperations(tty.TCSANOW, tty.SetNoEcho) @@ -685,6 +689,11 @@ func run_ssh(ssh_args, server_args, found_extra_args []string) (rc int, err erro return 1, err } } + go func() { + _ = <-sigs + // ignore any interrupt and terminate signals as they will usually be sent to the ssh child process as well + // and we are waiting on that. + }() err = c.Wait() drain_potential_tty_garbage(term) if err != nil {