mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-26 15:56:18 +02:00
Don't use std::cerr in a few places
Slightly scared of using std::cerr in a vforked process...
This commit is contained in:
parent
3acc8adcad
commit
8541d27fce
5 changed files with 34 additions and 30 deletions
|
@ -10,7 +10,6 @@
|
||||||
#include "immutable.hh"
|
#include "immutable.hh"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
@ -565,7 +564,7 @@ static void runSetuidHelper(const string & command,
|
||||||
throw SysError(format("executing `%1%'") % program);
|
throw SysError(format("executing `%1%'") % program);
|
||||||
}
|
}
|
||||||
catch (std::exception & e) {
|
catch (std::exception & e) {
|
||||||
std::cerr << "error: " << e.what() << std::endl;
|
writeToStderr("error: " + string(e.what()) + "\n");
|
||||||
}
|
}
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
|
@ -695,7 +694,7 @@ HookInstance::HookInstance()
|
||||||
throw SysError(format("executing `%1%'") % buildHook);
|
throw SysError(format("executing `%1%'") % buildHook);
|
||||||
|
|
||||||
} catch (std::exception & e) {
|
} catch (std::exception & e) {
|
||||||
std::cerr << format("build hook error: %1%") % e.what() << std::endl;
|
writeToStderr("build hook error: " + string(e.what()) + "\n");
|
||||||
}
|
}
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
|
@ -1547,7 +1546,7 @@ HookReply DerivationGoal::tryBuildHook()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
s += "\n";
|
s += "\n";
|
||||||
writeToStderr((unsigned char *) s.data(), s.size());
|
writeToStderr(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(format("hook reply is `%1%'") % reply);
|
debug(format("hook reply is `%1%'") % reply);
|
||||||
|
@ -2141,7 +2140,7 @@ void DerivationGoal::initChild()
|
||||||
throw SysError(format("executing `%1%'") % drv.builder);
|
throw SysError(format("executing `%1%'") % drv.builder);
|
||||||
|
|
||||||
} catch (std::exception & e) {
|
} catch (std::exception & e) {
|
||||||
std::cerr << format("build error: %1%") % e.what() << std::endl;
|
writeToStderr("build error: " + string(e.what()) + "\n");
|
||||||
_exit(inSetup ? childSetupFailed : 1);
|
_exit(inSetup ? childSetupFailed : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2362,7 +2361,7 @@ void DerivationGoal::handleChildOutput(int fd, const string & data)
|
||||||
(!hook && fd == builderOut.readSide))
|
(!hook && fd == builderOut.readSide))
|
||||||
{
|
{
|
||||||
if (verbosity >= settings.buildVerbosity)
|
if (verbosity >= settings.buildVerbosity)
|
||||||
writeToStderr((unsigned char *) data.data(), data.size());
|
writeToStderr(data);
|
||||||
if (bzLogFile) {
|
if (bzLogFile) {
|
||||||
int err;
|
int err;
|
||||||
BZ2_bzWrite(&err, bzLogFile, (unsigned char *) data.data(), data.size());
|
BZ2_bzWrite(&err, bzLogFile, (unsigned char *) data.data(), data.size());
|
||||||
|
@ -2372,7 +2371,7 @@ void DerivationGoal::handleChildOutput(int fd, const string & data)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hook && fd == hook->fromHook.readSide)
|
if (hook && fd == hook->fromHook.readSide)
|
||||||
writeToStderr((unsigned char *) data.data(), data.size());
|
writeToStderr(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2693,7 +2692,7 @@ void SubstitutionGoal::tryToRun()
|
||||||
throw SysError(format("executing `%1%'") % sub);
|
throw SysError(format("executing `%1%'") % sub);
|
||||||
|
|
||||||
} catch (std::exception & e) {
|
} catch (std::exception & e) {
|
||||||
std::cerr << format("substitute error: %1%") % e.what() << std::endl;
|
writeToStderr("substitute error: " + string(e.what()) + "\n");
|
||||||
}
|
}
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
|
@ -2809,8 +2808,7 @@ void SubstitutionGoal::finished()
|
||||||
void SubstitutionGoal::handleChildOutput(int fd, const string & data)
|
void SubstitutionGoal::handleChildOutput(int fd, const string & data)
|
||||||
{
|
{
|
||||||
assert(fd == logPipe.readSide);
|
assert(fd == logPipe.readSide);
|
||||||
if (verbosity >= settings.buildVerbosity)
|
if (verbosity >= settings.buildVerbosity) writeToStderr(data);
|
||||||
writeToStderr((unsigned char *) data.data(), data.size());
|
|
||||||
/* Don't write substitution output to a log file for now. We
|
/* Don't write substitution output to a log file for now. We
|
||||||
probably should, though. */
|
probably should, though. */
|
||||||
}
|
}
|
||||||
|
|
|
@ -556,7 +556,7 @@ void RemoteStore::processStderr(Sink * sink, Source * source)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
string s = readString(from);
|
string s = readString(from);
|
||||||
writeToStderr((const unsigned char *) s.data(), s.size());
|
writeToStderr(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (msg == STDERR_ERROR) {
|
if (msg == STDERR_ERROR) {
|
||||||
|
|
|
@ -483,16 +483,7 @@ void printMsg_(Verbosity level, const format & f)
|
||||||
else if (logType == ltEscapes && level != lvlInfo)
|
else if (logType == ltEscapes && level != lvlInfo)
|
||||||
prefix = "\033[" + escVerbosity(level) + "s";
|
prefix = "\033[" + escVerbosity(level) + "s";
|
||||||
string s = (format("%1%%2%\n") % prefix % f.str()).str();
|
string s = (format("%1%%2%\n") % prefix % f.str()).str();
|
||||||
try {
|
writeToStderr(s);
|
||||||
writeToStderr((const unsigned char *) s.data(), s.size());
|
|
||||||
} catch (SysError & e) {
|
|
||||||
/* Ignore failing writes to stderr if we're in an exception
|
|
||||||
handler, otherwise throw an exception. We need to ignore
|
|
||||||
write errors in exception handlers to ensure that cleanup
|
|
||||||
code runs to completion if the other side of stderr has
|
|
||||||
been closed unexpectedly. */
|
|
||||||
if (!std::uncaught_exception()) throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -505,13 +496,28 @@ void warnOnce(bool & haveWarned, const format & f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void writeToStderr(const string & s)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
_writeToStderr((const unsigned char *) s.data(), s.size());
|
||||||
|
} catch (SysError & e) {
|
||||||
|
/* Ignore failing writes to stderr if we're in an exception
|
||||||
|
handler, otherwise throw an exception. We need to ignore
|
||||||
|
write errors in exception handlers to ensure that cleanup
|
||||||
|
code runs to completion if the other side of stderr has
|
||||||
|
been closed unexpectedly. */
|
||||||
|
if (!std::uncaught_exception()) throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void defaultWriteToStderr(const unsigned char * buf, size_t count)
|
static void defaultWriteToStderr(const unsigned char * buf, size_t count)
|
||||||
{
|
{
|
||||||
writeFull(STDERR_FILENO, buf, count);
|
writeFull(STDERR_FILENO, buf, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void (*writeToStderr) (const unsigned char * buf, size_t count) = defaultWriteToStderr;
|
void (*_writeToStderr) (const unsigned char * buf, size_t count) = defaultWriteToStderr;
|
||||||
|
|
||||||
|
|
||||||
void readFull(int fd, unsigned char * buf, size_t count)
|
void readFull(int fd, unsigned char * buf, size_t count)
|
||||||
|
@ -845,8 +851,7 @@ void killUser(uid_t uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (std::exception & e) {
|
} catch (std::exception & e) {
|
||||||
std::cerr << format("killing processes belonging to uid `%1%': %2%")
|
writeToStderr((format("killing processes belonging to uid `%1%': %2%\n") % uid % e.what()).str());
|
||||||
% uid % e.what() << std::endl;
|
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
_exit(0);
|
_exit(0);
|
||||||
|
@ -902,7 +907,7 @@ string runProgram(Path program, bool searchPath, const Strings & args)
|
||||||
throw SysError(format("executing `%1%'") % program);
|
throw SysError(format("executing `%1%'") % program);
|
||||||
|
|
||||||
} catch (std::exception & e) {
|
} catch (std::exception & e) {
|
||||||
std::cerr << "error: " << e.what() << std::endl;
|
writeToStderr("error: " + string(e.what()) + "\n");
|
||||||
}
|
}
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,7 +148,9 @@ void printMsg_(Verbosity level, const format & f);
|
||||||
|
|
||||||
void warnOnce(bool & haveWarned, const format & f);
|
void warnOnce(bool & haveWarned, const format & f);
|
||||||
|
|
||||||
extern void (*writeToStderr) (const unsigned char * buf, size_t count);
|
void writeToStderr(const string & s);
|
||||||
|
|
||||||
|
extern void (*_writeToStderr) (const unsigned char * buf, size_t count);
|
||||||
|
|
||||||
|
|
||||||
/* Wrappers arount read()/write() that read/write exactly the
|
/* Wrappers arount read()/write() that read/write exactly the
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
#include "archive.hh"
|
#include "archive.hh"
|
||||||
#include "globals.hh"
|
#include "globals.hh"
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
@ -642,7 +641,7 @@ static void processConnection()
|
||||||
{
|
{
|
||||||
canSendStderr = false;
|
canSendStderr = false;
|
||||||
myPid = getpid();
|
myPid = getpid();
|
||||||
writeToStderr = tunnelStderr;
|
_writeToStderr = tunnelStderr;
|
||||||
|
|
||||||
#ifdef HAVE_HUP_NOTIFICATION
|
#ifdef HAVE_HUP_NOTIFICATION
|
||||||
/* Allow us to receive SIGPOLL for events on the client socket. */
|
/* Allow us to receive SIGPOLL for events on the client socket. */
|
||||||
|
@ -877,7 +876,7 @@ static void daemonLoop()
|
||||||
processConnection();
|
processConnection();
|
||||||
|
|
||||||
} catch (std::exception & e) {
|
} catch (std::exception & e) {
|
||||||
std::cerr << format("child error: %1%\n") % e.what();
|
writeToStderr("child error: " + string(e.what()) + "\n");
|
||||||
}
|
}
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue