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

Merge pull request #14687 from NixOS/repl-print-interrupt

libutil/signals: Get rid of setInterruptThrown
This commit is contained in:
John Ericson 2025-12-02 02:50:01 +00:00 committed by GitHub
commit 7f3ad17ac2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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 " ";
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) {

View file

@ -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
*/

View file

@ -12,24 +12,14 @@ using namespace unix;
std::atomic<bool> unix::_isInterrupted = false;
namespace unix {
static thread_local bool interruptThrown = false;
}
thread_local std::function<bool()> 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");
}
}

View file

@ -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 */