From 95a4d7037997d80f0ed9767b421653be819b6d28 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 29 May 2023 20:25:56 +1000 Subject: [PATCH] Kill current shell on during shell execution Closes #4907 --- src/shell_manager.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/shell_manager.cc b/src/shell_manager.cc index 96cfb063..62a60dc2 100644 --- a/src/shell_manager.cc +++ b/src/shell_manager.cc @@ -355,6 +355,7 @@ std::pair ShellManager::eval( client.redraw_ifn(); }, EventMode::Urgent}; + bool cancelling = false; while (not terminated or child_stdin.write_fd() != -1 or ((flags & Flags::WaitForStdout) and (child_stdout.read_fd() != -1 or child_stderr.read_fd() != -1))) @@ -363,6 +364,11 @@ std::pair ShellManager::eval( { EventManager::instance().handle_next_events(EventMode::Urgent, &orig_mask); } + catch (cancel&) + { + kill(pid, SIGINT); + cancelling = true; + } catch (runtime_error& error) { write_to_debug_buffer(format("error while waiting for shell: {}", error.what())); @@ -385,6 +391,9 @@ std::pair ShellManager::eval( (size_t)full.count(), (size_t)spawn.count(), (size_t)wait.count())); } + if (cancelling) + throw cancel{}; + if (previous_status) // restore the status line { context.print_status(std::move(*previous_status));