1313# include " nix/util/processes.hh"
1414#endif
1515
16+ #include < boost/regex.hpp>
17+
1618#include < functional>
1719#include < queue>
1820#include < algorithm>
19- #include < regex>
2021#include < random>
2122
2223#include < climits>
@@ -331,8 +332,8 @@ static void readProcLink(const std::filesystem::path & file, UncheckedRoots & ro
331332
332333static std::string quoteRegexChars (const std::string & raw)
333334{
334- static auto specialRegex = std ::regex (R"( [.^$\\*+?()\[\]{}|])" );
335- return std ::regex_replace (raw, specialRegex, R"( \$&)" );
335+ static auto specialRegex = boost ::regex (R"( [.^$\\*+?()\[\]{}|])" );
336+ return boost ::regex_replace (raw, specialRegex, R"( \$&)" );
336337}
337338
338339#ifdef __linux__
@@ -354,12 +355,12 @@ void LocalStore::findRuntimeRoots(Roots & roots, bool censor)
354355 auto procDir = AutoCloseDir{opendir (" /proc" )};
355356 if (procDir) {
356357 struct dirent * ent;
357- auto digitsRegex = std ::regex (R"( ^\d+$)" );
358- auto mapRegex = std ::regex (R"( ^\s*\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(/\S+)\s*$)" );
359- auto storePathRegex = std ::regex (quoteRegexChars (storeDir) + R"( /[0-9a-z]+[0-9a-zA-Z\+\-\._\?=]*)" );
358+ static const auto digitsRegex = boost ::regex (R"( ^\d+$)" );
359+ static const auto mapRegex = boost ::regex (R"( ^\s*\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(/\S+)\s*$)" );
360+ auto storePathRegex = boost ::regex (quoteRegexChars (storeDir) + R"( /[0-9a-z]+[0-9a-zA-Z\+\-\._\?=]*)" );
360361 while (errno = 0 , ent = readdir (procDir.get ())) {
361362 checkInterrupt ();
362- if (std ::regex_match (ent->d_name , digitsRegex)) {
363+ if (boost ::regex_match (ent->d_name , digitsRegex)) {
363364 try {
364365 readProcLink (fmt (" /proc/%s/exe" ,ent->d_name ), unchecked);
365366 readProcLink (fmt (" /proc/%s/cwd" , ent->d_name ), unchecked);
@@ -386,15 +387,15 @@ void LocalStore::findRuntimeRoots(Roots & roots, bool censor)
386387 std::filesystem::path mapFile = fmt (" /proc/%s/maps" , ent->d_name );
387388 auto mapLines = tokenizeString<std::vector<std::string>>(readFile (mapFile.string ()), " \n " );
388389 for (const auto & line : mapLines) {
389- auto match = std ::smatch{};
390- if (std ::regex_match (line, match, mapRegex))
390+ auto match = boost ::smatch{};
391+ if (boost ::regex_match (line, match, mapRegex))
391392 unchecked[match[1 ]].emplace (mapFile.string ());
392393 }
393394
394395 auto envFile = fmt (" /proc/%s/environ" , ent->d_name );
395396 auto envString = readFile (envFile);
396- auto env_end = std ::sregex_iterator{};
397- for (auto i = std ::sregex_iterator{envString.begin (), envString.end (), storePathRegex}; i != env_end; ++i)
397+ auto env_end = boost ::sregex_iterator{};
398+ for (auto i = boost ::sregex_iterator{envString.begin (), envString.end (), storePathRegex}; i != env_end; ++i)
398399 unchecked[i->str ()].emplace (envFile);
399400 } catch (SystemError & e) {
400401 if (errno == ENOENT || errno == EACCES || errno == ESRCH)
@@ -413,12 +414,12 @@ void LocalStore::findRuntimeRoots(Roots & roots, bool censor)
413414 // Because of this we disable lsof when running the tests.
414415 if (getEnv (" _NIX_TEST_NO_LSOF" ) != " 1" ) {
415416 try {
416- std ::regex lsofRegex (R"( ^n(/.*)$)" );
417+ boost ::regex lsofRegex (R"( ^n(/.*)$)" );
417418 auto lsofLines =
418419 tokenizeString<std::vector<std::string>>(runProgram (LSOF, true , { " -n" , " -w" , " -F" , " n" }), " \n " );
419420 for (const auto & line : lsofLines) {
420- std ::smatch match;
421- if (std ::regex_match (line, match, lsofRegex))
421+ boost ::smatch match;
422+ if (boost ::regex_match (line, match, lsofRegex))
422423 unchecked[match[1 ].str ()].emplace (" {lsof}" );
423424 }
424425 } catch (ExecError & e) {
0 commit comments