From 3839eb15d65163f30c9c5859a361302fcb4c447a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophane=20Hufschmitt?= Date: Mon, 11 Apr 2022 10:20:36 +0200 Subject: [PATCH] Also check the NixOS specific files --- src/nix-find-roots/nix-find-roots.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/nix-find-roots/nix-find-roots.cc b/src/nix-find-roots/nix-find-roots.cc index 06b5f272f..8ceb92521 100644 --- a/src/nix-find-roots/nix-find-roots.cc +++ b/src/nix-find-roots/nix-find-roots.cc @@ -197,6 +197,9 @@ TraceResult followPathsToStore(GlobalOpts opts, set roots) */ void scanFileContent(const GlobalOpts & opts, const fs::path & fileToScan, Roots & res) { + if (!fs::exists(fileToScan)) + return; + std::ostringstream contentStream; { std::ifstream fs; @@ -218,6 +221,9 @@ void scanFileContent(const GlobalOpts & opts, const fs::path & fileToScan, Roots */ void scanMapsFile(const GlobalOpts & opts, const fs::path & mapsFile, Roots & res) { + if (!fs::exists(mapsFile)) + return; + static auto mapRegex = std::regex(R"(^\s*\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(/\S+)\s*$)"); std::stringstream mappedFile; { @@ -275,6 +281,13 @@ Roots getRuntimeRoots(GlobalOpts opts) scanFileContent(opts, procEntry.path()/"environ", res); scanMapsFile(opts, procEntry.path()/"maps", res); } + + // Mostly useful for NixOS, but doesn’t hurt to check on other systems + // anyways + scanFileContent(opts, "/proc/sys/kernel/modprobe", res); + scanFileContent(opts, "/proc/sys/kernel/fbsplash", res); + scanFileContent(opts, "/proc/sys/kernel/poweroff_cmd", res); + return res; }