* Log the output of builders to $prefix/var/log/nix.

This commit is contained in:
Eelco Dolstra 2003-05-30 15:21:52 +00:00
parent 64582f54be
commit d1f5fd7216
2 changed files with 76 additions and 50 deletions

View File

@ -1,6 +1,6 @@
bin_PROGRAMS = nix fix
CXXFLAGS = -DSYSTEM=\"@host@\" -Wall
AM_CXXFLAGS = -DSYSTEM=\"@host@\" -Wall
nix_SOURCES = nix.cc db.cc util.cc md5.c
nix_LDADD = -ldb_cxx-4 -lATerm
@ -16,5 +16,6 @@ install-data-local:
$(INSTALL) -d $(localstatedir)/nix/prebuilts
$(INSTALL) -d $(localstatedir)/nix/prebuilts/imports
$(INSTALL) -d $(localstatedir)/nix/prebuilts/exports
$(INSTALL) -d $(localstatedir)/log/nix
$(INSTALL) -d $(prefix)/pkg
$(bindir)/nix init

View File

@ -29,6 +29,7 @@ static string dbNetSources = "netsources";
static string nixSourcesDir;
static string nixLogDir;
static string nixDB;
@ -228,6 +229,13 @@ void installPkg(string hash)
if (mkdir(path.c_str(), 0777))
throw Error("unable to create directory " + path);
/* Create a log file. */
string logFileName = nixLogDir + "/" + id + "-" + hash + ".log";
/* !!! auto-pclose on exit */
FILE * logFile = popen(("tee " + logFileName).c_str(), "w"); /* !!! escaping */
if (!logFile)
throw Error("unable to create log file " + logFileName);
try {
/* Fork a child to build the package. */
@ -237,7 +245,9 @@ void installPkg(string hash)
case -1:
throw Error("unable to fork");
case 0: { /* child */
case 0:
try { /* child */
/* Go to the build directory. */
if (chdir(path.c_str())) {
@ -267,10 +277,11 @@ void installPkg(string hash)
_exit(0);
}
build:
build:
/* Fill in the environment. We don't bother freeing the
strings, since we'll exec or die soon anyway. */
/* Fill in the environment. We don't bother freeing
the strings, since we'll exec or die soon
anyway. */
const char * env2[env.size() + 1];
int i = 0;
for (Environment::iterator it = env.begin();
@ -278,21 +289,34 @@ build:
env2[i] = (new string(it->first + "=" + it->second))->c_str();
env2[i] = 0;
/* Dup the log handle into stderr. */
if (dup2(fileno(logFile), STDERR_FILENO) == -1)
throw Error("cannot pipe standard error into log file: " + string(strerror(errno)));
/* Dup stderr to stdin. */
dup2(STDERR_FILENO, STDOUT_FILENO);
if (dup2(STDERR_FILENO, STDOUT_FILENO) == -1)
throw Error("cannot dup stderr into stdout");
/* Execute the builder. This should not return. */
execle(builder.c_str(), builder.c_str(), 0, env2);
cerr << strerror(errno) << endl;
throw Error("unable to execute builder: " +
string(strerror(errno)));
cerr << "unable to execute builder\n";
_exit(1); }
} catch (exception & e) {
cerr << "build error: " << e.what() << endl;
_exit(1);
}
}
/* parent */
/* Close the logging pipe. Note that this should not cause
the logger to exit until builder exits (because the latter
has an open file handle to the former). */
pclose(logFile);
/* Wait for the child to finish. */
int status;
if (waitpid(pid, &status, 0) != pid)
@ -690,6 +714,7 @@ void run(Strings::iterator argCur, Strings::iterator argEnd)
if (homeDir) nixHomeDir = homeDir;
nixSourcesDir = nixHomeDir + "/var/nix/sources";
nixLogDir = nixHomeDir + "/var/log/nix";
nixDB = nixHomeDir + "/var/nix/pkginfo.db";
/* Parse the global flags. */