From 9dbfe242e3bdbfc7728a36c8a2b9fbbea2c8ed68 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 8 Dec 2006 15:44:00 +0000 Subject: * Kill a build if it has gone for more than a certain number of seconds without producing output on stdout or stderr (NIX-65). This timeout can be specified using the `--max-silent-time' option or the `build-max-silent-time' configuration setting. The default is infinity (0). * Fix a tricky race condition: if we kill the build user before the child has done its setuid() to the build user uid, then it won't be killed, and we'll potentially lock up in pid.wait(). So also send a conventional kill to the child. --- src/libmain/shared.cc | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'src/libmain/shared.cc') diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index d7fb240192..f1a7db40dc 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -57,6 +57,18 @@ static void setLogType(string lt) } +static unsigned int getIntArg(const string & opt, + Strings::iterator & i, const Strings::iterator & end) +{ + ++i; + if (i == end) throw UsageError(format("`%1%' requires an argument") % opt); + int n; + if (!string2Int(*i, n) || n < 0) + throw UsageError(format("`%1%' requires a non-negative integer") % opt); + return n; +} + + struct RemoveTempRoots { ~RemoveTempRoots() @@ -91,12 +103,8 @@ static void initAndRun(int argc, char * * argv) /* Get some settings from the configuration file. */ thisSystem = querySetting("system", SYSTEM); - { - int n; - if (!string2Int(querySetting("build-max-jobs", "1"), n) || n < 0) - throw Error("invalid value for configuration setting `build-max-jobs'"); - maxBuildJobs = n; - } + maxBuildJobs = queryIntSetting("build-max-jobs", 1); + maxSilentTime = queryIntSetting("build-max-silent-time", 0); /* Catch SIGINT. */ struct sigaction act, oact; @@ -180,16 +188,12 @@ static void initAndRun(int argc, char * * argv) keepGoing = true; else if (arg == "--fallback") tryFallback = true; - else if (arg == "--max-jobs" || arg == "-j") { - ++i; - if (i == args.end()) throw UsageError("`--max-jobs' requires an argument"); - int n; - if (!string2Int(*i, n) || n < 0) - throw UsageError(format("`--max-jobs' requires a non-negative integer")); - maxBuildJobs = n; - } + else if (arg == "--max-jobs" || arg == "-j") + maxBuildJobs = getIntArg(arg, i, args.end()); else if (arg == "--readonly-mode") readOnlyMode = true; + else if (arg == "--max-silent-time") + maxSilentTime = getIntArg(arg, i, args.end()); else remaining.push_back(arg); } -- cgit 1.4.1