From efe428946431c6c670151c949884fa8c1fa31794 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 2 Sep 2013 11:58:18 +0200 Subject: Add an option to limit the log output of builders This is mostly useful for Hydra to deal with builders that get stuck in an infinite loop writing data to stdout/stderr. --- src/libstore/build.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/libstore/build.cc') diff --git a/src/libstore/build.cc b/src/libstore/build.cc index b5d064e8c60d..25bf848ca697 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -813,6 +813,9 @@ private: BZFILE * bzLogFile; AutoCloseFD fdLogFile; + /* Number of bytes received from the builder's stdout/stderr. */ + unsigned long logSize; + /* Pipe for the builder's standard output/error. */ Pipe builderOut; @@ -2403,6 +2406,8 @@ string drvsLogDir = "drvs"; Path DerivationGoal::openLogFile() { + logSize = 0; + if (!settings.keepLog) return ""; string baseName = baseNameOf(drvPath); @@ -2478,6 +2483,14 @@ void DerivationGoal::handleChildOutput(int fd, const string & data) if ((hook && fd == hook->builderOut.readSide) || (!hook && fd == builderOut.readSide)) { + logSize += data.size(); + if (settings.maxLogSize && logSize > settings.maxLogSize) { + printMsg(lvlError, + format("%1% killed after writing more than %2% bytes of log output") + % getName() % settings.maxLogSize); + cancel(true); // not really a timeout, but close enough + return; + } if (verbosity >= settings.buildVerbosity) writeToStderr(data); if (bzLogFile) { -- cgit 1.4.1