libstore: asyncify LocalStore::findPlatformRoots
Change-Id: I173fae8aa17cb757b9c2aceadb4d68259a236b32
This commit is contained in:
+7
-3
@@ -359,8 +359,8 @@ try {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
void LocalStore::findPlatformRoots(UncheckedRoots & unchecked)
|
||||
{
|
||||
kj::Promise<Result<void>> LocalStore::findPlatformRoots(UncheckedRoots & unchecked)
|
||||
try {
|
||||
// N.B. This is (read: undertested!) fallback code only used for
|
||||
// non-Darwin, non-Linux platforms. Both major platforms have
|
||||
// platform-specific code in lix/libstore/platform/
|
||||
@@ -376,13 +376,17 @@ void LocalStore::findPlatformRoots(UncheckedRoots & unchecked)
|
||||
} catch (ExecError & e) {
|
||||
/* lsof not installed, lsof failed */
|
||||
}
|
||||
|
||||
co_return result::success();
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
kj::Promise<Result<void>> LocalStore::findRuntimeRoots(Roots & roots, bool censor)
|
||||
try {
|
||||
UncheckedRoots unchecked;
|
||||
|
||||
findPlatformRoots(unchecked);
|
||||
TRY_AWAIT(findPlatformRoots(unchecked));
|
||||
|
||||
for (auto & [target, links] : unchecked) {
|
||||
if (!isInStore(target)) continue;
|
||||
|
||||
@@ -393,7 +393,7 @@ private:
|
||||
* Find possible garbage collector roots in a platform-specific manner,
|
||||
* e.g. by looking in `/proc` or using `lsof`
|
||||
*/
|
||||
virtual void findPlatformRoots(UncheckedRoots & unchecked);
|
||||
virtual kj::Promise<Result<void>> findPlatformRoots(UncheckedRoots & unchecked);
|
||||
|
||||
kj::Promise<Result<void>> findRuntimeRoots(Roots & roots, bool censor);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "lix/libstore/gc-store.hh"
|
||||
#include "lix/libutil/result.hh"
|
||||
#include "lix/libutil/signals.hh"
|
||||
#include "lix/libstore/platform/darwin.hh"
|
||||
#include "lix/libutil/regex.hh"
|
||||
@@ -14,8 +15,8 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
void DarwinLocalStore::findPlatformRoots(UncheckedRoots & unchecked)
|
||||
{
|
||||
kj::Promise<Result<void>> DarwinLocalStore::findPlatformRoots(UncheckedRoots & unchecked)
|
||||
try {
|
||||
auto storePathRegex = regex::storePathRegex(config().storeDir);
|
||||
|
||||
std::vector<int> pids;
|
||||
@@ -240,6 +241,10 @@ void DarwinLocalStore::findPlatformRoots(UncheckedRoots & unchecked)
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
co_return result::success();
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
void DarwinLocalDerivationGoal::execBuilder(std::string builder, Strings args, Strings envStrs)
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
void findPlatformRoots(UncheckedRoots & unchecked) override;
|
||||
kj::Promise<Result<void>> findPlatformRoots(UncheckedRoots & unchecked) override;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "lix/libutil/finally.hh"
|
||||
#include "lix/libstore/gc-store.hh"
|
||||
#include "lix/libutil/processes.hh"
|
||||
#include "lix/libutil/result.hh"
|
||||
#include "lix/libutil/signals.hh"
|
||||
#include "lix/libstore/platform/linux.hh"
|
||||
#include "lix/libutil/regex.hh"
|
||||
@@ -79,8 +80,8 @@ LinuxLocalDerivationGoal::~LinuxLocalDerivationGoal()
|
||||
}
|
||||
}
|
||||
|
||||
void LinuxLocalStore::findPlatformRoots(UncheckedRoots & unchecked)
|
||||
{
|
||||
kj::Promise<Result<void>> LinuxLocalStore::findPlatformRoots(UncheckedRoots & unchecked)
|
||||
try {
|
||||
auto procDir = AutoCloseDir{opendir("/proc")};
|
||||
if (procDir) {
|
||||
struct dirent * ent;
|
||||
@@ -154,6 +155,10 @@ void LinuxLocalStore::findPlatformRoots(UncheckedRoots & unchecked)
|
||||
readFileRoots("/proc/sys/kernel/modprobe", unchecked);
|
||||
readFileRoots("/proc/sys/kernel/fbsplash", unchecked);
|
||||
readFileRoots("/proc/sys/kernel/poweroff_cmd", unchecked);
|
||||
|
||||
co_return result::success();
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
#if HAVE_SECCOMP
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
void findPlatformRoots(UncheckedRoots & unchecked) override;
|
||||
kj::Promise<Result<void>> findPlatformRoots(UncheckedRoots & unchecked) override;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user