From c0c1bde506d4f2d499ff5d0b7220b67ce08c8e89 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Tue, 2 Dec 2025 00:59:49 +0300 Subject: [PATCH] libutil/signals: Get rid of setInterruptThrown The interrupting code is no longer relevant. Since 054be5025762c5e1c7e853c4fa5d7eed8da1727f logging no longer checks for interrupts and in general logging should be noexcept. Co-authored-by: Alois Wohlschlager Cherry-picked-from: https://gerrit.lix.systems/c/lix/+/1097 --- doc/manual/rl-next/repl-interrupt.md | 8 ++++++++ src/libmain/shared.cc | 11 +---------- src/libutil/include/nix/util/signals.hh | 5 ----- src/libutil/unix/signals.cc | 12 +----------- src/libutil/windows/include/nix/util/signals-impl.hh | 5 ----- 5 files changed, 10 insertions(+), 31 deletions(-) create mode 100644 doc/manual/rl-next/repl-interrupt.md diff --git a/doc/manual/rl-next/repl-interrupt.md b/doc/manual/rl-next/repl-interrupt.md new file mode 100644 index 000000000..7e7e45ed6 --- /dev/null +++ b/doc/manual/rl-next/repl-interrupt.md @@ -0,0 +1,8 @@ +--- +synopsis: Interrupting REPL commands works more than once +issues: [13481] +--- + +Previously, this only worked once per REPL session; further attempts would be ignored. +This issue is now fixed, so REPL commands such as `:b` or `:p` can be canceled consistently. +This is a cherry-pick of the change from the [Lix project](https://gerrit.lix.systems/c/lix/+/1097). diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index 19733fb3e..8a59e3dac 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -321,16 +321,7 @@ int handleExceptions(const std::string & programName, std::function fun) std::string error = ANSI_RED "error:" ANSI_NORMAL " "; try { - try { - fun(); - } catch (...) { - /* Subtle: we have to make sure that any `interrupted' - condition is discharged before we reach printMsg() - below, since otherwise it will throw an (uncaught) - exception. */ - setInterruptThrown(); - throw; - } + fun(); } catch (Exit & e) { return e.status; } catch (UsageError & e) { diff --git a/src/libutil/include/nix/util/signals.hh b/src/libutil/include/nix/util/signals.hh index 8facec37f..ff26975ad 100644 --- a/src/libutil/include/nix/util/signals.hh +++ b/src/libutil/include/nix/util/signals.hh @@ -21,11 +21,6 @@ static inline void setInterrupted(bool isInterrupted); */ static inline bool getInterrupted(); -/** - * @note Does nothing on Windows - */ -void setInterruptThrown(); - /** * @note Does nothing on Windows */ diff --git a/src/libutil/unix/signals.cc b/src/libutil/unix/signals.cc index d6efd6aa7..de441492a 100644 --- a/src/libutil/unix/signals.cc +++ b/src/libutil/unix/signals.cc @@ -12,24 +12,14 @@ using namespace unix; std::atomic unix::_isInterrupted = false; -namespace unix { -static thread_local bool interruptThrown = false; -} - thread_local std::function unix::interruptCheck; -void setInterruptThrown() -{ - unix::interruptThrown = true; -} - void unix::_interrupted() { /* Block user interrupts while an exception is being handled. Throwing an exception while another exception is being handled kills the program! */ - if (!interruptThrown && !std::uncaught_exceptions()) { - interruptThrown = true; + if (!std::uncaught_exceptions()) { throw Interrupted("interrupted by the user"); } } diff --git a/src/libutil/windows/include/nix/util/signals-impl.hh b/src/libutil/windows/include/nix/util/signals-impl.hh index d1c79cab9..af5a5336e 100644 --- a/src/libutil/windows/include/nix/util/signals-impl.hh +++ b/src/libutil/windows/include/nix/util/signals-impl.hh @@ -17,11 +17,6 @@ static inline bool getInterrupted() return false; } -inline void setInterruptThrown() -{ - /* Do nothing for now */ -} - static inline bool isInterrupted() { /* Do nothing for now */