aboutsummaryrefslogtreecommitdiff
path: root/src/nix-daemon/nix-daemon.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix-daemon/nix-daemon.cc')
-rw-r--r--src/nix-daemon/nix-daemon.cc116
1 files changed, 69 insertions, 47 deletions
diff --git a/src/nix-daemon/nix-daemon.cc b/src/nix-daemon/nix-daemon.cc
index 5189c9b4c..3c2e05210 100644
--- a/src/nix-daemon/nix-daemon.cc
+++ b/src/nix-daemon/nix-daemon.cc
@@ -33,29 +33,43 @@ using namespace nix;
static FdSource from(STDIN_FILENO);
static FdSink to(STDOUT_FILENO);
-bool canSendStderr;
+static bool canSendStderr;
+static Logger * defaultLogger;
-/* This function is called anytime we want to write something to
- stderr. If we're in a state where the protocol allows it (i.e.,
- when canSendStderr), send the message to the client over the
- socket. */
-static void tunnelStderr(const unsigned char * buf, size_t count)
+
+/* Logger that forwards log messages to the client, *if* we're in a
+ state where the protocol allows it (i.e., when canSendStderr is
+ true). */
+class TunnelLogger : public Logger
{
- if (canSendStderr) {
- try {
- to << STDERR_NEXT;
- writeString(buf, count, to);
- to.flush();
- } catch (...) {
- /* Write failed; that means that the other side is
- gone. */
- canSendStderr = false;
- throw;
- }
- } else
- writeFull(STDERR_FILENO, buf, count);
-}
+ void log(Verbosity lvl, const FormatOrString & fs) override
+ {
+ if (lvl > verbosity) return;
+
+ if (canSendStderr) {
+ try {
+ to << STDERR_NEXT << (fs.s + "\n");
+ to.flush();
+ } catch (...) {
+ /* Write failed; that means that the other side is
+ gone. */
+ canSendStderr = false;
+ throw;
+ }
+ } else
+ defaultLogger->log(lvl, fs);
+ }
+
+ void startActivity(Activity & activity, Verbosity lvl, const FormatOrString & fs) override
+ {
+ log(lvl, fs);
+ }
+
+ void stopActivity(Activity & activity) override
+ {
+ }
+};
/* startWork() means that we're starting an operation for which we
@@ -199,7 +213,7 @@ static void performOp(ref<LocalStore> store, bool trusted, unsigned int clientVe
case wopQueryPathHash: {
Path path = readStorePath(from);
startWork();
- Hash hash = store->queryPathHash(path);
+ auto hash = store->queryPathInfo(path)->narHash;
stopWork();
to << printHash(hash);
break;
@@ -213,7 +227,7 @@ static void performOp(ref<LocalStore> store, bool trusted, unsigned int clientVe
startWork();
PathSet paths;
if (op == wopQueryReferences)
- store->queryReferences(path, paths);
+ paths = store->queryPathInfo(path)->references;
else if (op == wopQueryReferrers)
store->queryReferrers(path, paths);
else if (op == wopQueryValidDerivers)
@@ -237,7 +251,7 @@ static void performOp(ref<LocalStore> store, bool trusted, unsigned int clientVe
case wopQueryDeriver: {
Path path = readStorePath(from);
startWork();
- Path deriver = store->queryDeriver(path);
+ auto deriver = store->queryPathInfo(path)->deriver;
stopWork();
to << deriver;
break;
@@ -429,9 +443,9 @@ static void performOp(ref<LocalStore> store, bool trusted, unsigned int clientVe
if (GET_PROTOCOL_MINOR(clientVersion) >= 2)
settings.useBuildHook = readInt(from) != 0;
if (GET_PROTOCOL_MINOR(clientVersion) >= 4) {
- settings.buildVerbosity = (Verbosity) readInt(from);
- logType = (LogType) readInt(from);
- settings.printBuildTrace = readInt(from) != 0;
+ settings.verboseBuild = lvlError == (Verbosity) readInt(from);
+ readInt(from); // obsolete logType
+ readInt(from); // obsolete printBuildTrace
}
if (GET_PROTOCOL_MINOR(clientVersion) >= 6)
settings.set("build-cores", std::to_string(readInt(from)));
@@ -493,30 +507,25 @@ static void performOp(ref<LocalStore> store, bool trusted, unsigned int clientVe
break;
}
- case wopQueryFailedPaths: {
- startWork();
- PathSet paths = store->queryFailedPaths();
- stopWork();
- to << paths;
- break;
- }
-
- case wopClearFailedPaths: {
- PathSet paths = readStrings<PathSet>(from);
- startWork();
- store->clearFailedPaths(paths);
- stopWork();
- to << 1;
- break;
- }
-
case wopQueryPathInfo: {
Path path = readStorePath(from);
+ std::shared_ptr<const ValidPathInfo> info;
startWork();
- ValidPathInfo info = store->queryPathInfo(path);
+ try {
+ info = store->queryPathInfo(path);
+ } catch (InvalidPath &) {
+ if (GET_PROTOCOL_MINOR(clientVersion) < 17) throw;
+ }
stopWork();
- to << info.deriver << printHash(info.narHash) << info.references
- << info.registrationTime << info.narSize;
+ if (info) {
+ to << 1 << info->deriver << printHash(info->narHash) << info->references
+ << info->registrationTime << info->narSize;
+ if (GET_PROTOCOL_MINOR(clientVersion) >= 16) {
+ to << info->ultimate
+ << info->sigs;
+ }
+ } else
+ to << 0;
break;
}
@@ -539,6 +548,18 @@ static void performOp(ref<LocalStore> store, bool trusted, unsigned int clientVe
break;
}
+ case wopAddSignatures: {
+ Path path = readStorePath(from);
+ StringSet sigs = readStrings<StringSet>(from);
+ startWork();
+ if (!trusted)
+ throw Error("you are not privileged to add signatures");
+ store->addSignatures(path, sigs);
+ stopWork();
+ to << 1;
+ break;
+ }
+
default:
throw Error(format("invalid operation %1%") % op);
}
@@ -550,7 +571,8 @@ static void processConnection(bool trusted)
MonitorFdHup monitor(from.fd);
canSendStderr = false;
- _writeToStderr = tunnelStderr;
+ defaultLogger = logger;
+ logger = new TunnelLogger();
/* Exchange the greeting. */
unsigned int magic = readInt(from);