1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-05 08:31:00 +01:00

libutil/signals: Get rid of setInterruptThrown

The interrupting code is no longer relevant. Since
054be50257 logging no longer checks for interrupts
and in general logging should be noexcept.

Co-authored-by: Alois Wohlschlager <alois1@gmx-topmail.de>
Cherry-picked-from: https://gerrit.lix.systems/c/lix/+/1097
This commit is contained in:
Sergei Zimmerman 2025-12-02 00:59:49 +03:00
parent 048a58d331
commit c0c1bde506
No known key found for this signature in database
5 changed files with 10 additions and 31 deletions

View file

@ -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).

View file

@ -321,16 +321,7 @@ int handleExceptions(const std::string & programName, std::function<void()> fun)
std::string error = ANSI_RED "error:" ANSI_NORMAL " "; std::string error = ANSI_RED "error:" ANSI_NORMAL " ";
try { try {
try { fun();
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;
}
} catch (Exit & e) { } catch (Exit & e) {
return e.status; return e.status;
} catch (UsageError & e) { } catch (UsageError & e) {

View file

@ -21,11 +21,6 @@ static inline void setInterrupted(bool isInterrupted);
*/ */
static inline bool getInterrupted(); static inline bool getInterrupted();
/**
* @note Does nothing on Windows
*/
void setInterruptThrown();
/** /**
* @note Does nothing on Windows * @note Does nothing on Windows
*/ */

View file

@ -12,24 +12,14 @@ using namespace unix;
std::atomic<bool> unix::_isInterrupted = false; std::atomic<bool> unix::_isInterrupted = false;
namespace unix {
static thread_local bool interruptThrown = false;
}
thread_local std::function<bool()> unix::interruptCheck; thread_local std::function<bool()> unix::interruptCheck;
void setInterruptThrown()
{
unix::interruptThrown = true;
}
void unix::_interrupted() void unix::_interrupted()
{ {
/* Block user interrupts while an exception is being handled. /* Block user interrupts while an exception is being handled.
Throwing an exception while another exception is being handled Throwing an exception while another exception is being handled
kills the program! */ kills the program! */
if (!interruptThrown && !std::uncaught_exceptions()) { if (!std::uncaught_exceptions()) {
interruptThrown = true;
throw Interrupted("interrupted by the user"); throw Interrupted("interrupted by the user");
} }
} }

View file

@ -17,11 +17,6 @@ static inline bool getInterrupted()
return false; return false;
} }
inline void setInterruptThrown()
{
/* Do nothing for now */
}
static inline bool isInterrupted() static inline bool isInterrupted()
{ {
/* Do nothing for now */ /* Do nothing for now */