From a4ff9b0d080e2fea3dd504379876139933b8f725 Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <eelco.dolstra@logicblox.com>
Date: Thu, 4 Oct 2012 14:31:47 -0400
Subject: [PATCH] hydra-eval-jobs: Don't go into an infinite recursion

The function getDerivation() can return false if its argument is a
derivation.  This happens if evaluating the name or system attribute
triggers an assertion.  In that case, we shouldn't recurse into the
attributes of the derivation.
---
 src/c/hydra-eval-jobs.cc | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/c/hydra-eval-jobs.cc b/src/c/hydra-eval-jobs.cc
index b1915fbd..c8cb125b 100644
--- a/src/c/hydra-eval-jobs.cc
+++ b/src/c/hydra-eval-jobs.cc
@@ -16,7 +16,7 @@ using namespace nix;
 
 void printHelp()
 {
-    std::cout << "Syntax: eval-jobs <expr>\n";
+    std::cout << "Syntax: hydra-eval-jobs <expr>\n";
 }
 
 
@@ -110,6 +110,8 @@ static void findJobsWrapped(EvalState & state, XMLWriter & doc,
 {
     debug(format("at path `%1%'") % attrPath);
 
+    checkInterrupt();
+
     state.forceValue(v);
 
     if (v.type == tAttrs) {
@@ -165,9 +167,11 @@ static void findJobsWrapped(EvalState & state, XMLWriter & doc,
         }
 
         else {
-            foreach (Bindings::iterator, i, *v.attrs)
-                findJobs(state, doc, argsUsed, argsLeft, *i->value,
-                    (attrPath.empty() ? "" : attrPath + ".") + (string) i->name);
+            if (!state.isDerivation(v)) {
+                foreach (Bindings::iterator, i, *v.attrs)
+                    findJobs(state, doc, argsUsed, argsLeft, *i->value,
+                        (attrPath.empty() ? "" : attrPath + ".") + (string) i->name);
+            }
         }
     }
 
@@ -261,4 +265,4 @@ void run(Strings args)
 }
 
 
-string programId = "eval-jobs";
+string programId = "hydra-eval-jobs";