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

View file

@ -29,6 +29,7 @@ static string dbNetSources = "netsources";
static string nixSourcesDir; static string nixSourcesDir;
static string nixLogDir;
static string nixDB; static string nixDB;
@ -228,6 +229,13 @@ void installPkg(string hash)
if (mkdir(path.c_str(), 0777)) if (mkdir(path.c_str(), 0777))
throw Error("unable to create directory " + path); 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 { try {
/* Fork a child to build the package. */ /* Fork a child to build the package. */
@ -237,7 +245,9 @@ void installPkg(string hash)
case -1: case -1:
throw Error("unable to fork"); throw Error("unable to fork");
case 0: { /* child */ case 0:
try { /* child */
/* Go to the build directory. */ /* Go to the build directory. */
if (chdir(path.c_str())) { if (chdir(path.c_str())) {
@ -269,8 +279,9 @@ void installPkg(string hash)
build: build:
/* Fill in the environment. We don't bother freeing the /* Fill in the environment. We don't bother freeing
strings, since we'll exec or die soon anyway. */ the strings, since we'll exec or die soon
anyway. */
const char * env2[env.size() + 1]; const char * env2[env.size() + 1];
int i = 0; int i = 0;
for (Environment::iterator it = env.begin(); for (Environment::iterator it = env.begin();
@ -278,21 +289,34 @@ build:
env2[i] = (new string(it->first + "=" + it->second))->c_str(); env2[i] = (new string(it->first + "=" + it->second))->c_str();
env2[i] = 0; 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. */ /* 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. */ /* Execute the builder. This should not return. */
execle(builder.c_str(), builder.c_str(), 0, env2); 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"; } catch (exception & e) {
_exit(1); } cerr << "build error: " << e.what() << endl;
_exit(1);
}
} }
/* parent */ /* 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. */ /* Wait for the child to finish. */
int status; int status;
if (waitpid(pid, &status, 0) != pid) if (waitpid(pid, &status, 0) != pid)
@ -690,6 +714,7 @@ void run(Strings::iterator argCur, Strings::iterator argEnd)
if (homeDir) nixHomeDir = homeDir; if (homeDir) nixHomeDir = homeDir;
nixSourcesDir = nixHomeDir + "/var/nix/sources"; nixSourcesDir = nixHomeDir + "/var/nix/sources";
nixLogDir = nixHomeDir + "/var/log/nix";
nixDB = nixHomeDir + "/var/nix/pkginfo.db"; nixDB = nixHomeDir + "/var/nix/pkginfo.db";
/* Parse the global flags. */ /* Parse the global flags. */