aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2024-10-01 15:30:30 -0700
committerRebecca Turner <rbt@sent.as>2024-10-01 15:49:56 -0700
commitee0c195eba7d16b796fd9883e3fe88c0d64ff0bf (patch)
tree1048d5203ed5780274bbbd3992f986a5df6a1981 /src/libstore
parent775292766025380d04004e42fefbdb8ca40b3fa3 (diff)
Split ignoreException to avoid suppressing CTRL-C
This splits `ignoreException` into `ignoreExceptionExceptInterrupt` (which ignores all exceptions except `Interrupt`, which indicates a SIGINT/CTRL-C) and `ignoreExceptionInDestructor` (which ignores all exceptions, so that destructors do not throw exceptions). This prevents many cases where Nix ignores CTRL-C entirely. See: https://github.com/NixOS/nix/issues/7245 Upstream-PR: https://github.com/NixOS/nix/pull/11618 Change-Id: Ie7d2467eedbe840d1b9fa2e88a4e88e4ab26a87b
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/build/derivation-goal.cc4
-rw-r--r--src/libstore/build/hook-instance.cc3
-rw-r--r--src/libstore/build/local-derivation-goal.cc9
-rw-r--r--src/libstore/build/substitution-goal.cc2
-rw-r--r--src/libstore/filetransfer.cc2
-rw-r--r--src/libstore/gc.cc4
-rw-r--r--src/libstore/local-store.cc4
-rw-r--r--src/libstore/optimise-store.cc2
-rw-r--r--src/libstore/pathlocks.cc2
-rw-r--r--src/libstore/pathlocks.hh3
-rw-r--r--src/libstore/remote-fs-accessor.cc4
-rw-r--r--src/libstore/remote-store.cc5
-rw-r--r--src/libstore/sqlite.cc6
-rw-r--r--src/libstore/store-api.cc2
14 files changed, 28 insertions, 24 deletions
diff --git a/src/libstore/build/derivation-goal.cc b/src/libstore/build/derivation-goal.cc
index 5c0452391..fe2bb0145 100644
--- a/src/libstore/build/derivation-goal.cc
+++ b/src/libstore/build/derivation-goal.cc
@@ -107,7 +107,7 @@ DerivationGoal::~DerivationGoal() noexcept(false)
{
/* Careful: we should never ever throw an exception from a
destructor. */
- try { closeLogFile(); } catch (...) { ignoreException(); }
+ try { closeLogFile(); } catch (...) { ignoreExceptionInDestructor(); }
}
@@ -858,7 +858,7 @@ void replaceValidPath(const Path & storePath, const Path & tmpPath)
// attempt to recover
movePath(oldPath, storePath);
} catch (...) {
- ignoreException();
+ ignoreExceptionExceptInterrupt();
}
throw;
}
diff --git a/src/libstore/build/hook-instance.cc b/src/libstore/build/hook-instance.cc
index f91a904cc..521f34917 100644
--- a/src/libstore/build/hook-instance.cc
+++ b/src/libstore/build/hook-instance.cc
@@ -1,4 +1,5 @@
#include "child.hh"
+#include "error.hh"
#include "file-system.hh"
#include "globals.hh"
#include "hook-instance.hh"
@@ -86,7 +87,7 @@ HookInstance::~HookInstance()
toHook.reset();
if (pid) pid.kill();
} catch (...) {
- ignoreException();
+ ignoreExceptionInDestructor();
}
}
diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc
index f3d0bc8b4..5c1fcf1f8 100644
--- a/src/libstore/build/local-derivation-goal.cc
+++ b/src/libstore/build/local-derivation-goal.cc
@@ -1,4 +1,5 @@
#include "local-derivation-goal.hh"
+#include "error.hh"
#include "indirect-root-store.hh"
#include "machines.hh"
#include "store-api.hh"
@@ -98,9 +99,9 @@ LocalDerivationGoal::~LocalDerivationGoal() noexcept(false)
{
/* Careful: we should never ever throw an exception from a
destructor. */
- try { deleteTmpDir(false); } catch (...) { ignoreException(); }
- try { killChild(); } catch (...) { ignoreException(); }
- try { stopDaemon(); } catch (...) { ignoreException(); }
+ try { deleteTmpDir(false); } catch (...) { ignoreExceptionInDestructor(); }
+ try { killChild(); } catch (...) { ignoreExceptionInDestructor(); }
+ try { stopDaemon(); } catch (...) { ignoreExceptionInDestructor(); }
}
@@ -1249,7 +1250,7 @@ void LocalDerivationGoal::startDaemon()
NotTrusted, daemon::Recursive);
debug("terminated daemon connection");
} catch (SysError &) {
- ignoreException();
+ ignoreExceptionExceptInterrupt();
}
});
diff --git a/src/libstore/build/substitution-goal.cc b/src/libstore/build/substitution-goal.cc
index 8088bf668..6dddf6e40 100644
--- a/src/libstore/build/substitution-goal.cc
+++ b/src/libstore/build/substitution-goal.cc
@@ -291,7 +291,7 @@ void PathSubstitutionGoal::cleanup()
thr.get();
}
} catch (...) {
- ignoreException();
+ ignoreExceptionInDestructor();
}
}
diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc
index 10c810e49..6fe1f9a05 100644
--- a/src/libstore/filetransfer.cc
+++ b/src/libstore/filetransfer.cc
@@ -115,7 +115,7 @@ struct curlFileTransfer : public FileTransfer
if (!done)
fail(FileTransferError(Interrupted, {}, "download of '%s' was interrupted", request.uri));
} catch (...) {
- ignoreException();
+ ignoreExceptionInDestructor();
}
}
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index d5903d01e..99bf80994 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -923,8 +923,8 @@ void LocalStore::autoGC(bool sync)
} catch (...) {
// FIXME: we could propagate the exception to the
- // future, but we don't really care.
- ignoreException();
+ // future, but we don't really care. (what??)
+ ignoreExceptionInDestructor();
}
}).detach();
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 1af0f54de..c3248c2c3 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -481,7 +481,7 @@ LocalStore::~LocalStore()
unlink(fnTempRoots.c_str());
}
} catch (...) {
- ignoreException();
+ ignoreExceptionInDestructor();
}
}
@@ -1222,7 +1222,7 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source,
try {
parseDump(sink, source);
} catch (...) {
- ignoreException();
+ ignoreExceptionExceptInterrupt();
}
}
};
diff --git a/src/libstore/optimise-store.cc b/src/libstore/optimise-store.cc
index c60e5a85d..14381b6e0 100644
--- a/src/libstore/optimise-store.cc
+++ b/src/libstore/optimise-store.cc
@@ -31,7 +31,7 @@ struct MakeReadOnly
/* This will make the path read-only. */
if (path != "") canonicaliseTimestampAndPermissions(path);
} catch (...) {
- ignoreException();
+ ignoreExceptionInDestructor();
}
}
};
diff --git a/src/libstore/pathlocks.cc b/src/libstore/pathlocks.cc
index ced0f30bb..3225857ec 100644
--- a/src/libstore/pathlocks.cc
+++ b/src/libstore/pathlocks.cc
@@ -145,7 +145,7 @@ PathLocks::~PathLocks()
try {
unlock();
} catch (...) {
- ignoreException();
+ ignoreExceptionInDestructor();
}
}
diff --git a/src/libstore/pathlocks.hh b/src/libstore/pathlocks.hh
index d06d031b5..feb0f5548 100644
--- a/src/libstore/pathlocks.hh
+++ b/src/libstore/pathlocks.hh
@@ -1,6 +1,7 @@
#pragma once
///@file
+#include "error.hh"
#include "file-descriptor.hh"
namespace nix {
@@ -53,7 +54,7 @@ struct FdLock
if (acquired)
lockFile(fd, ltNone, false);
} catch (SysError &) {
- ignoreException();
+ ignoreExceptionInDestructor();
}
}
};
diff --git a/src/libstore/remote-fs-accessor.cc b/src/libstore/remote-fs-accessor.cc
index 0689ce74d..59d267873 100644
--- a/src/libstore/remote-fs-accessor.cc
+++ b/src/libstore/remote-fs-accessor.cc
@@ -29,7 +29,7 @@ ref<FSAccessor> RemoteFSAccessor::addToCache(std::string_view hashPart, std::str
/* FIXME: do this asynchronously. */
writeFile(makeCacheFile(hashPart, "nar"), nar);
} catch (...) {
- ignoreException();
+ ignoreExceptionExceptInterrupt();
}
}
@@ -41,7 +41,7 @@ ref<FSAccessor> RemoteFSAccessor::addToCache(std::string_view hashPart, std::str
nlohmann::json j = listNar(narAccessor, "", true);
writeFile(makeCacheFile(hashPart, "ls"), j.dump());
} catch (...) {
- ignoreException();
+ ignoreExceptionExceptInterrupt();
}
}
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index 1f94ca03f..a9f9818be 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -1,3 +1,4 @@
+#include "error.hh"
#include "serialise.hh"
#include "signals.hh"
#include "path-with-outputs.hh"
@@ -855,7 +856,7 @@ RemoteStore::Connection::~Connection()
try {
to.flush();
} catch (...) {
- ignoreException();
+ ignoreExceptionInDestructor();
}
}
@@ -985,7 +986,7 @@ void RemoteStore::ConnectionHandle::withFramedSink(std::function<void(Sink & sin
try {
std::rethrow_exception(ex);
} catch (...) {
- ignoreException();
+ ignoreExceptionExceptInterrupt();
}
}
}
diff --git a/src/libstore/sqlite.cc b/src/libstore/sqlite.cc
index 8d0bfcb11..7aa0b6629 100644
--- a/src/libstore/sqlite.cc
+++ b/src/libstore/sqlite.cc
@@ -85,7 +85,7 @@ SQLite::~SQLite()
if (db && sqlite3_close(db) != SQLITE_OK)
SQLiteError::throw_(db, "closing database");
} catch (...) {
- ignoreException();
+ ignoreExceptionInDestructor();
}
}
@@ -124,7 +124,7 @@ SQLiteStmt::~SQLiteStmt()
if (stmt && sqlite3_finalize(stmt) != SQLITE_OK)
SQLiteError::throw_(db, "finalizing statement '%s'", sql);
} catch (...) {
- ignoreException();
+ ignoreExceptionInDestructor();
}
}
@@ -248,7 +248,7 @@ SQLiteTxn::~SQLiteTxn()
if (active && sqlite3_exec(db, "rollback;", 0, 0, 0) != SQLITE_OK)
SQLiteError::throw_(db, "aborting transaction");
} catch (...) {
- ignoreException();
+ ignoreExceptionInDestructor();
}
}
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index 50d392779..d35a0e6a1 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -1163,7 +1163,7 @@ std::map<StorePath, StorePath> copyPaths(
// not be within our control to change that, and we might still want
// to at least copy the output paths.
if (e.missingFeature == Xp::CaDerivations)
- ignoreException();
+ ignoreExceptionExceptInterrupt();
else
throw;
}