From d331d3a0b5c497a46e2636f308234be66566c04c Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 20 May 2020 04:33:07 +0100 Subject: refactor(3p/nix): Apply clang-tidy's modernize-* fixes This applies the modernization fixes listed here: https://clang.llvm.org/extra/clang-tidy/checks/list.html The 'modernize-use-trailing-return-type' fix was excluded due to my personal preference (more specifically, I think the 'auto' keyword is misleading in that position). --- third_party/nix/src/nix-daemon/nix-daemon.cc | 47 ++++++++++++++-------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'third_party/nix/src/nix-daemon') diff --git a/third_party/nix/src/nix-daemon/nix-daemon.cc b/third_party/nix/src/nix-daemon/nix-daemon.cc index e3ebb4767894..14c3eb7ed278 100644 --- a/third_party/nix/src/nix-daemon/nix-daemon.cc +++ b/third_party/nix/src/nix-daemon/nix-daemon.cc @@ -1,13 +1,13 @@ #include +#include +#include +#include #include -#include #include #include #include -#include #include -#include #include #include #include @@ -74,7 +74,8 @@ struct TunnelLogger { unsigned int clientVersion; - explicit TunnelLogger(unsigned int clientVersion) : clientVersion(clientVersion) {} + explicit TunnelLogger(unsigned int clientVersion) + : clientVersion(clientVersion) {} void enqueueMsg(const std::string& s) { auto state(state_.lock()); @@ -152,7 +153,7 @@ struct TunnelLogger { struct TunnelSink : Sink { Sink& to; explicit TunnelSink(Sink& to) : to(to) {} - virtual void operator()(const unsigned char* data, size_t len) { + void operator()(const unsigned char* data, size_t len) override { to << STDERR_WRITE; writeString(data, len, to); } @@ -177,18 +178,18 @@ struct TunnelSource : BufferedSource { /* If the NAR archive contains a single file at top-level, then save the contents of the file to `s'. Otherwise barf. */ struct RetrieveRegularNARSink : ParseSink { - bool regular; + bool regular{true}; string s; - RetrieveRegularNARSink() : regular(true) {} + RetrieveRegularNARSink() {} - void createDirectory(const Path& path) { regular = false; } + void createDirectory(const Path& path) override { regular = false; } - void receiveContents(unsigned char* data, unsigned int len) { + void receiveContents(unsigned char* data, unsigned int len) override { s.append((const char*)data, len); } - void createSymlink(const Path& path, const string& target) { + void createSymlink(const Path& path, const string& target) override { regular = false; } }; @@ -213,7 +214,7 @@ static void performOp(TunnelLogger* logger, ref store, bool trusted, } case wopQueryValidPaths: { - PathSet paths = readStorePaths(*store, from); + auto paths = readStorePaths(*store, from); logger->startWork(); PathSet res = store->queryValidPaths(paths); logger->stopWork(); @@ -231,7 +232,7 @@ static void performOp(TunnelLogger* logger, ref store, bool trusted, } case wopQuerySubstitutablePaths: { - PathSet paths = readStorePaths(*store, from); + auto paths = readStorePaths(*store, from); logger->startWork(); PathSet res = store->querySubstitutablePaths(paths); logger->stopWork(); @@ -343,7 +344,7 @@ static void performOp(TunnelLogger* logger, ref store, bool trusted, case wopAddTextToStore: { string suffix = readString(from); string s = readString(from); - PathSet refs = readStorePaths(*store, from); + auto refs = readStorePaths(*store, from); logger->startWork(); Path path = store->addTextToStore(suffix, s, refs, NoRepair); logger->stopWork(); @@ -373,7 +374,7 @@ static void performOp(TunnelLogger* logger, ref store, bool trusted, } case wopBuildPaths: { - PathSet drvs = readStorePaths(*store, from); + auto drvs = readStorePaths(*store, from); BuildMode mode = bmNormal; if (GET_PROTOCOL_MINOR(clientVersion) >= 15) { mode = (BuildMode)readInt(from); @@ -397,7 +398,7 @@ static void performOp(TunnelLogger* logger, ref store, bool trusted, Path drvPath = readStorePath(*store, from); BasicDerivation drv; readDerivation(from, *store, drv); - BuildMode buildMode = (BuildMode)readInt(from); + auto buildMode = (BuildMode)readInt(from); logger->startWork(); if (!trusted) { throw Error("you are not privileged to build derivations"); @@ -570,7 +571,7 @@ static void performOp(TunnelLogger* logger, ref store, bool trusted, SubstitutablePathInfos infos; store->querySubstitutablePathInfos({path}, infos); logger->stopWork(); - SubstitutablePathInfos::iterator i = infos.find(path); + auto i = infos.find(path); if (i == infos.end()) { to << 0; } else { @@ -581,7 +582,7 @@ static void performOp(TunnelLogger* logger, ref store, bool trusted, } case wopQuerySubstitutablePathInfos: { - PathSet paths = readStorePaths(*store, from); + auto paths = readStorePaths(*store, from); logger->startWork(); SubstitutablePathInfos infos; store->querySubstitutablePathInfos(paths, infos); @@ -652,7 +653,7 @@ static void performOp(TunnelLogger* logger, ref store, bool trusted, case wopAddSignatures: { Path path = readStorePath(*store, from); - StringSet sigs = readStrings(from); + auto sigs = readStrings(from); logger->startWork(); if (!trusted) { throw Error("you are not privileged to add signatures"); @@ -713,7 +714,7 @@ static void performOp(TunnelLogger* logger, ref store, bool trusted, } case wopQueryMissing: { - PathSet targets = readStorePaths(*store, from); + auto targets = readStorePaths(*store, from); logger->startWork(); PathSet willBuild, willSubstitute, unknown; unsigned long long downloadSize, narSize; @@ -834,7 +835,7 @@ static void sigChldHandler(int sigNo) { // Ensure we don't modify errno of whatever we've interrupted auto saved_errno = errno; /* Reap all dead children. */ - while (waitpid(-1, 0, WNOHANG) > 0) { + while (waitpid(-1, nullptr, WNOHANG) > 0) { ; } errno = saved_errno; @@ -991,7 +992,7 @@ static void daemonLoop(char** argv) { closeOnExec(fdSocket.get()); /* Loop accepting connections. */ - while (1) { + while (true) { try { /* Accept a connection. */ struct sockaddr_un remoteAddr; @@ -1012,10 +1013,10 @@ static void daemonLoop(char** argv) { bool trusted = false; PeerInfo peer = getPeerInfo(remote.get()); - struct passwd* pw = peer.uidKnown ? getpwuid(peer.uid) : 0; + struct passwd* pw = peer.uidKnown ? getpwuid(peer.uid) : nullptr; string user = pw ? pw->pw_name : std::to_string(peer.uid); - struct group* gr = peer.gidKnown ? getgrgid(peer.gid) : 0; + struct group* gr = peer.gidKnown ? getgrgid(peer.gid) : nullptr; string group = gr ? gr->gr_name : std::to_string(peer.gid); Strings trustedUsers = settings.trustedUsers; -- cgit 1.4.1