From 4e17be7981026f0317fb12f166282be2d972889e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 3 Feb 2010 21:38:41 +0000 Subject: [PATCH] * Revert r19797, and use a simpler solution: just don't monitor build hooks for silence. It's unnecessary because the remote nix-store command is already monitoring the real build. --- src/libmain/shared.cc | 13 ------------- src/libstore/build.cc | 28 ++++++++++++++++++---------- src/libstore/pathlocks.cc | 14 ++------------ src/libstore/pathlocks.hh | 3 +-- 4 files changed, 21 insertions(+), 37 deletions(-) diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index d48e2ad696..d9cf9a8626 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -31,11 +31,6 @@ static void sigintHandler(int signo) } -static void sigalrmHandler(int signo) -{ -} - - Path makeRootName(const Path & gcRoot, int & counter) { counter++; @@ -165,14 +160,6 @@ static void initAndRun(int argc, char * * argv) if (sigaction(SIGPIPE, &act, 0)) throw SysError("ignoring SIGPIPE"); - /* Catch SIGALRM with an empty handler (we just need it to get an - EINTR from blocking system calls). */ - act.sa_handler = sigalrmHandler; - sigfillset(&act.sa_mask); - act.sa_flags = 0; - if (sigaction(SIGALRM, &act, 0)) - throw SysError("installing handler for SIGALRM"); - /* Reset SIGCHLD to its default. */ act.sa_handler = SIG_DFL; act.sa_flags = 0; diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 77cffba25d..f4478a4db2 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -162,6 +162,7 @@ struct Child { WeakGoalPtr goal; set fds; + bool monitorForSilence; bool inBuildSlot; time_t lastOutput; /* time we last got output on stdout/stderr */ }; @@ -234,7 +235,7 @@ public: /* Registers a running child process. `inBuildSlot' means that the process counts towards the jobs limit. */ void childStarted(GoalPtr goal, pid_t pid, - const set & fds, bool inBuildSlot); + const set & fds, bool inBuildSlot, bool monitorForSilence); /* Unregisters a running child process. `wakeSleepers' should be false if there is no sense in waking up goals that are sleeping @@ -1262,7 +1263,7 @@ DerivationGoal::HookReply DerivationGoal::tryBuildHook() pid.setKillSignal(SIGTERM); logPipe.writeSide.close(); worker.childStarted(shared_from_this(), - pid, singleton >(logPipe.readSide), false); + pid, singleton >(logPipe.readSide), false, false); toHook.readSide.close(); @@ -1767,7 +1768,7 @@ void DerivationGoal::startBuilder() pid.setSeparatePG(true); logPipe.writeSide.close(); worker.childStarted(shared_from_this(), pid, - singleton >(logPipe.readSide), true); + singleton >(logPipe.readSide), true, true); if (printBuildTrace) { printMsg(lvlError, format("@ build-started %1% %2% %3% %4%") @@ -2274,7 +2275,7 @@ void SubstitutionGoal::tryToRun() pid.setKillSignal(SIGTERM); logPipe.writeSide.close(); worker.childStarted(shared_from_this(), - pid, singleton >(logPipe.readSide), true); + pid, singleton >(logPipe.readSide), true, true); state = &SubstitutionGoal::finished; @@ -2474,13 +2475,15 @@ unsigned Worker::getNrLocalBuilds() void Worker::childStarted(GoalPtr goal, - pid_t pid, const set & fds, bool inBuildSlot) + pid_t pid, const set & fds, bool inBuildSlot, + bool monitorForSilence) { Child child; child.goal = goal; child.fds = fds; child.lastOutput = time(0); child.inBuildSlot = inBuildSlot; + child.monitorForSilence = monitorForSilence; children[pid] = child; if (inBuildSlot) nrLocalBuilds++; } @@ -2601,12 +2604,16 @@ void Worker::waitForInput() if (maxSilentTime != 0) { time_t oldest = 0; foreach (Children::iterator, i, children) { - oldest = oldest == 0 || i->second.lastOutput < oldest - ? i->second.lastOutput : oldest; + if (i->second.monitorForSilence) { + oldest = oldest == 0 || i->second.lastOutput < oldest + ? i->second.lastOutput : oldest; + } + } + if (oldest) { + useTimeout = true; + timeout.tv_sec = std::max((time_t) 0, oldest + maxSilentTime - before); + printMsg(lvlVomit, format("sleeping %1% seconds") % timeout.tv_sec); } - useTimeout = true; - timeout.tv_sec = std::max((time_t) 0, oldest + maxSilentTime - before); - printMsg(lvlVomit, format("sleeping %1% seconds") % timeout.tv_sec); } /* If we are polling goals that are waiting for a lock, then wake @@ -2681,6 +2688,7 @@ void Worker::waitForInput() } if (maxSilentTime != 0 && + j->second.monitorForSilence && after - j->second.lastOutput >= (time_t) maxSilentTime) { printMsg(lvlError, diff --git a/src/libstore/pathlocks.cc b/src/libstore/pathlocks.cc index fe872ceede..d8290815c4 100644 --- a/src/libstore/pathlocks.cc +++ b/src/libstore/pathlocks.cc @@ -37,8 +37,7 @@ void deleteLockFile(const Path & path, int fd) } -bool lockFile(int fd, LockType lockType, bool wait, - unsigned int progressInterval) +bool lockFile(int fd, LockType lockType, bool wait) { struct flock lock; if (lockType == ltRead) lock.l_type = F_RDLCK; @@ -50,20 +49,11 @@ bool lockFile(int fd, LockType lockType, bool wait, lock.l_len = 0; /* entire file */ if (wait) { - /* Wait until we acquire the lock. If `progressInterval' is - non-zero, when print a message every `progressInterval' - seconds. This is mostly to make sure that remote builders - aren't killed due to the `max-silent-time' inactivity - monitor while waiting for the garbage collector lock. */ - while (1) { - if (progressInterval) alarm(progressInterval); - if (fcntl(fd, F_SETLKW, &lock) == 0) break; + while (fcntl(fd, F_SETLKW, &lock) != 0) { checkInterrupt(); if (errno != EINTR) throw SysError(format("acquiring/releasing lock")); - if (progressInterval) printMsg(lvlError, "still waiting for lock..."); } - alarm(0); } else { while (fcntl(fd, F_SETLK, &lock) != 0) { checkInterrupt(); diff --git a/src/libstore/pathlocks.hh b/src/libstore/pathlocks.hh index 8c6ac6a03f..57ca1584a6 100644 --- a/src/libstore/pathlocks.hh +++ b/src/libstore/pathlocks.hh @@ -17,8 +17,7 @@ void deleteLockFile(const Path & path, int fd); enum LockType { ltRead, ltWrite, ltNone }; -bool lockFile(int fd, LockType lockType, bool wait, - unsigned int progressInterval = 300); +bool lockFile(int fd, LockType lockType, bool wait); class PathLocks