From 53b24f351852498c52377c2f011617af04bc76fa Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 17 Jul 2012 09:40:12 -0400 Subject: [PATCH] Allow disabling log compression --- doc/manual/conf-file.xml | 10 ++++++++++ src/libstore/build.cc | 37 +++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/doc/manual/conf-file.xml b/doc/manual/conf-file.xml index 7fd104eb4..1b19e56b5 100644 --- a/doc/manual/conf-file.xml +++ b/doc/manual/conf-file.xml @@ -297,6 +297,16 @@ build-use-chroot = /dev /proc /bin + build-compress-log + + If set to true (the default), + build logs written to /nix/var/log/nix/drvs + will be compressed on the fly using bzip2. Otherwise, they will + not be compressed. + + + + system This option specifies the canonical Nix system diff --git a/src/libstore/build.cc b/src/libstore/build.cc index d5bbd540b..8eb5dfa41 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -769,6 +769,7 @@ private: /* File descriptor for the log file. */ FILE * fLogFile; BZFILE * bzLogFile; + AutoCloseFD fdLogFile; /* Pipe for the builder's standard output/error. */ Pipe builderOut; @@ -2119,20 +2120,29 @@ Path DerivationGoal::openLogFile() Path dir = (format("%1%/%2%") % nixLogDir % drvsLogDir).str(); createDirs(dir); - Path logFileName = (format("%1%/%2%.bz2") % dir % baseNameOf(drvPath)).str(); - AutoCloseFD fd = open(logFileName.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0666); - if (fd == -1) - throw SysError(format("creating log file `%1%'") % logFileName); - closeOnExec(fd); + if (queryBoolSetting("build-compress-log", true)) { - if (!(fLogFile = fdopen(fd.borrow(), "w"))) - throw SysError(format("opening file `%1%'") % logFileName); + Path logFileName = (format("%1%/%2%.bz2") % dir % baseNameOf(drvPath)).str(); + AutoCloseFD fd = open(logFileName.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0666); + if (fd == -1) throw SysError(format("creating log file `%1%'") % logFileName); + closeOnExec(fd); - int err; - if (!(bzLogFile = BZ2_bzWriteOpen(&err, fLogFile, 9, 0, 0))) - throw Error(format("cannot open compressed log file `%1%'") % logFileName); + if (!(fLogFile = fdopen(fd.borrow(), "w"))) + throw SysError(format("opening file `%1%'") % logFileName); - return logFileName; + int err; + if (!(bzLogFile = BZ2_bzWriteOpen(&err, fLogFile, 9, 0, 0))) + throw Error(format("cannot open compressed log file `%1%'") % logFileName); + + return logFileName; + + } else { + Path logFileName = (format("%1%/%2%") % dir % baseNameOf(drvPath)).str(); + fdLogFile = open(logFileName.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0666); + if (fdLogFile == -1) throw SysError(format("creating log file `%1%'") % logFileName); + closeOnExec(fdLogFile); + return logFileName; + } } @@ -2149,6 +2159,8 @@ void DerivationGoal::closeLogFile() fclose(fLogFile); fLogFile = 0; } + + fdLogFile.close(); } @@ -2180,7 +2192,8 @@ void DerivationGoal::handleChildOutput(int fd, const string & data) int err; BZ2_bzWrite(&err, bzLogFile, (unsigned char *) data.data(), data.size()); if (err != BZ_OK) throw Error(format("cannot write to compressed log file (BZip2 error = %1%)") % err); - } + } else if (fdLogFile != -1) + writeFull(fdLogFile, (unsigned char *) data.data(), data.size()); } if (hook && fd == hook->fromHook.readSide)