[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
05/27: Ensure we're writing to stderr in the builder
From: |
Ludovic Courtès |
Subject: |
05/27: Ensure we're writing to stderr in the builder |
Date: |
Wed, 03 Jun 2015 22:00:34 +0000 |
civodul pushed a commit to branch nix
in repository guix.
commit 5c84e4950d8504e386fc1f454fb4653993a8fbea
Author: Eelco Dolstra <address@hidden>
Date: Fri Dec 12 14:35:44 2014 +0100
Ensure we're writing to stderr in the builder
http://hydra.nixos.org/build/17862041
---
nix/libstore/build.cc | 6 +++---
nix/libstore/gc.cc | 4 ++--
nix/libstore/pathlocks.cc | 2 +-
nix/libutil/util.cc | 27 ++++++++++++++-------------
nix/libutil/util.hh | 1 +
5 files changed, 21 insertions(+), 19 deletions(-)
diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc
index ccffd8d..3250b04 100644
--- a/nix/libstore/build.cc
+++ b/nix/libstore/build.cc
@@ -2203,7 +2203,7 @@ void DerivationGoal::runChild()
restoreSIGPIPE();
/* Indicate that we managed to set up the build environment. */
- writeToStderr("\n");
+ writeFull(STDERR_FILENO, "\n");
/* Execute the program. This should not return. */
execve(program.c_str(), (char * *) &args[0], (char * *) envArr);
@@ -2211,7 +2211,7 @@ void DerivationGoal::runChild()
throw SysError(format("executing `%1%'") % drv.builder);
} catch (std::exception & e) {
- writeToStderr("while setting up the build environment: " +
string(e.what()) + "\n");
+ writeFull(STDERR_FILENO, "while setting up the build environment: " +
string(e.what()) + "\n");
_exit(1);
}
@@ -2526,7 +2526,7 @@ void DerivationGoal::handleChildOutput(int fd, const
string & data)
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());
+ writeFull(fdLogFile, data);
}
if (hook && fd == hook->fromHook.readSide)
diff --git a/nix/libstore/gc.cc b/nix/libstore/gc.cc
index f98e02c..885a459 100644
--- a/nix/libstore/gc.cc
+++ b/nix/libstore/gc.cc
@@ -191,7 +191,7 @@ void LocalStore::addTempRoot(const Path & path)
lockFile(fdTempRoots, ltWrite, true);
string s = path + '\0';
- writeFull(fdTempRoots, (const unsigned char *) s.data(), s.size());
+ writeFull(fdTempRoots, s);
/* Downgrade to a read lock. */
debug(format("downgrading to read lock on `%1%'") % fnTempRoots);
@@ -231,7 +231,7 @@ static void readTempRoots(PathSet & tempRoots, FDs & fds)
if (lockFile(*fd, ltWrite, false)) {
printMsg(lvlError, format("removing stale temporary roots file
`%1%'") % path);
unlink(path.c_str());
- writeFull(*fd, (const unsigned char *) "d", 1);
+ writeFull(*fd, "d");
continue;
}
diff --git a/nix/libstore/pathlocks.cc b/nix/libstore/pathlocks.cc
index b858ed2..830858f 100644
--- a/nix/libstore/pathlocks.cc
+++ b/nix/libstore/pathlocks.cc
@@ -33,7 +33,7 @@ void deleteLockFile(const Path & path, int fd)
other processes waiting on this lock that the lock is stale
(deleted). */
unlink(path.c_str());
- writeFull(fd, (const unsigned char *) "d", 1);
+ writeFull(fd, "d");
/* Note that the result of unlink() is ignored; removing the lock
file is an optimisation, not a necessity. */
}
diff --git a/nix/libutil/util.cc b/nix/libutil/util.cc
index 9bb6ba3..4d6090d 100644
--- a/nix/libutil/util.cc
+++ b/nix/libutil/util.cc
@@ -264,8 +264,8 @@ void writeFile(const Path & path, const string & s)
{
AutoCloseFD fd = open(path.c_str(), O_WRONLY | O_TRUNC | O_CREAT, 0666);
if (fd == -1)
- throw SysError(format("opening file `%1%'") % path);
- writeFull(fd, (unsigned char *) s.data(), s.size());
+ throw SysError(format("opening file '%1%'") % path);
+ writeFull(fd, s);
}
@@ -292,7 +292,7 @@ string readLine(int fd)
void writeLine(int fd, string s)
{
s += '\n';
- writeFull(fd, (const unsigned char *) s.data(), s.size());
+ writeFull(fd, s);
}
@@ -482,18 +482,13 @@ void warnOnce(bool & haveWarned, const FormatOrString &
fs)
}
-static void defaultWriteToStderr(const unsigned char * buf, size_t count)
-{
- writeFull(STDERR_FILENO, buf, count);
-}
-
-
void writeToStderr(const string & s)
{
try {
- auto p = _writeToStderr;
- if (!p) p = defaultWriteToStderr;
- p((const unsigned char *) s.data(), s.size());
+ if (_writeToStderr)
+ _writeToStderr((const unsigned char *) s.data(), s.size());
+ else
+ writeFull(STDERR_FILENO, s);
} catch (SysError & e) {
/* Ignore failing writes to stderr if we're in an exception
handler, otherwise throw an exception. We need to ignore
@@ -505,7 +500,7 @@ void writeToStderr(const string & s)
}
-void (*_writeToStderr) (const unsigned char * buf, size_t count) =
defaultWriteToStderr;
+void (*_writeToStderr) (const unsigned char * buf, size_t count) = 0;
void readFull(int fd, unsigned char * buf, size_t count)
@@ -539,6 +534,12 @@ void writeFull(int fd, const unsigned char * buf, size_t
count)
}
+void writeFull(int fd, const string & s)
+{
+ writeFull(fd, (const unsigned char *) s.data(), s.size());
+}
+
+
string drainFD(int fd)
{
string result;
diff --git a/nix/libutil/util.hh b/nix/libutil/util.hh
index 0ad0026..8a48a2b 100644
--- a/nix/libutil/util.hh
+++ b/nix/libutil/util.hh
@@ -171,6 +171,7 @@ extern void (*_writeToStderr) (const unsigned char * buf,
size_t count);
requested number of bytes. */
void readFull(int fd, unsigned char * buf, size_t count);
void writeFull(int fd, const unsigned char * buf, size_t count);
+void writeFull(int fd, const string & s);
MakeError(EndOfFile, Error)
- branch nix updated (3bfa70b -> e531520), Ludovic Courtès, 2015/06/03
- 01/27: Rename 'initChild' to 'runChild'., Ludovic Courtès, 2015/06/03
- 02/27: Use PR_SET_PDEATHSIG to ensure child cleanup, Ludovic Courtès, 2015/06/03
- 04/27: Get rid of unnecessary "interrupted by the user" message with -vvv, Ludovic Courtès, 2015/06/03
- 03/27: Remove tabs, Ludovic Courtès, 2015/06/03
- 07/27: Shut up a Valgrind warning, Ludovic Courtès, 2015/06/03
- 06/27: Fix some memory leaks, Ludovic Courtès, 2015/06/03
- 08/27: Silence some warnings on GCC 4.9, Ludovic Courtès, 2015/06/03
- 09/27: Better error message, Ludovic Courtès, 2015/06/03
- 10/27: Explicitly include required C headers, Ludovic Courtès, 2015/06/03
- 05/27: Ensure we're writing to stderr in the builder,
Ludovic Courtès <=
- 12/27: libutil: Improve errmsg on readLink size mismatch., Ludovic Courtès, 2015/06/03
- 13/27: libutil: Limit readLink() error to only overflows., Ludovic Courtès, 2015/06/03
- 11/27: Pedantry, Ludovic Courtès, 2015/06/03
- 14/27: Set /nix/store permission to 1737, Ludovic Courtès, 2015/06/03
- 16/27: Doh^2, Ludovic Courtès, 2015/06/03
- 17/27: Simplify printHash32, Ludovic Courtès, 2015/06/03
- 18/27: Simplify parseHash32, Ludovic Courtès, 2015/06/03
- 19/27: Use pivot_root in addition to chroot when possible, Ludovic Courtès, 2015/06/03
- 15/27: Doh, Ludovic Courtès, 2015/06/03
- 22/27: Tighten permissions on chroot directories, Ludovic Courtès, 2015/06/03