]> git.ipfire.org Git - thirdparty/make.git/commitdiff
[SV 56918] Compute job slots properly on failing command
authorPaul Smith <psmith@gnu.org>
Sat, 21 Sep 2019 19:11:21 +0000 (15:11 -0400)
committerPaul Smith <psmith@gnu.org>
Sat, 21 Sep 2019 19:38:48 +0000 (15:38 -0400)
Ensure we properly reduce job_slots_used if a command fails because
it doesn't exist/can't be started.

* src/job.h (struct child): Add a field jobslot to be set when using
a job slot.
* src/job.c (start_waiting_job): Remember if we are using a job slot.
(reap_children): Reduce number of job slots used by jobslot.

src/job.c
src/job.h
tests/scripts/features/errors

index c7e7f7953e6116460f369447f556bc37c9ddc655..ba3770ce8c61c9955336f94853a17cf41faa4e5f 100644 (file)
--- a/src/job.c
+++ b/src/job.c
@@ -1073,12 +1073,12 @@ reap_children (int block, int err)
         {
           DB (DB_JOBS, (_("Removing child %p PID %s%s from chain.\n"),
                         c, pid2str (c->pid), c->remote ? _(" (remote)") : ""));
-
-          /* There is now another slot open.  */
-          if (job_slots_used > 0)
-            --job_slots_used;
         }
 
+      /* There is now another slot open.  */
+      if (job_slots_used > 0)
+        job_slots_used -= c->jobslot;
+
       /* Remove the child from the chain and free it.  */
       if (lastc == 0)
         children = c->next;
@@ -1647,6 +1647,8 @@ start_waiting_job (struct child *c)
                         c->remote ? _(" (remote)") : ""));
           /* One more job slot is in use.  */
           ++job_slots_used;
+          assert (c->jobslot == 0);
+          c->jobslot = 1;
         }
       children = c;
       unblock_sigs ();
index 4f1da97c0e4ea78bd5c39d8172e7dfc28acb47f2..e20866a2140887e1c55b63224ce13e94c2cb5baa 100644 (file)
--- a/src/job.h
+++ b/src/job.h
@@ -61,6 +61,7 @@ struct child
     unsigned int  good_stdin:1; /* Nonzero if this child has a good stdin.  */
     unsigned int  deleted:1;    /* Nonzero if targets have been deleted.  */
     unsigned int  recursive:1;  /* Nonzero for recursive command ('+' etc.)  */
+    unsigned int  jobslot:1;    /* Nonzero if it's reserved a job slot.  */
     unsigned int  dontcare:1;   /* Saved dontcare flag.  */
   };
 
index 1e1556229fee9b5f9835c4f92180998966702841..06b496a37d6a4d520a77f5b11fdc57845886a172 100644 (file)
@@ -42,21 +42,31 @@ my $err = $ERR_no_such_file;
 
 run_make_test(qq!
 one: ; -$unk xx yy
-two: ; $unk aa bb
 !,
               'one', "$unk xx yy\n#MAKE#: $unk: $err\n#MAKE#: [#MAKEFILE#;2: one] Error 127 (ignored)\n");
 
 # TEST #4
 # -------
 
-run_make_test(undef, 'two -i',
-              "$unk aa bb\n#MAKE#: $unk: $err\n#MAKE#: [#MAKEFILE#;3: two] Error 127 (ignored)\n");
+run_make_test(qq!
+two: ; $unk aa bb
+!, 'two -i',
+              "$unk aa bb\n#MAKE#: $unk: $err\n#MAKE#: [#MAKEFILE#;2: two] Error 127 (ignored)\n");
 
 # TEST #5
 # -------
 
 run_make_test(undef, 'two',
-              "$unk aa bb\n#MAKE#: $unk: $err\n#MAKE#: *** [#MAKEFILE#;3: two] Error 127\n", 512);
+              "$unk aa bb\n#MAKE#: $unk: $err\n#MAKE#: *** [#MAKEFILE#;2: two] Error 127\n", 512);
+
+# SV #56918 : Test the unknown command as the second recipe line
+
+run_make_test(qq!
+three:
+\t\@echo one
+\t$unk qq rr
+!, 'three',
+              "one\n$unk qq rr\n#MAKE#: $unk: $err\n#MAKE#: *** [#MAKEFILE#;4: three] Error 127\n", 512);
 
 # Try failing due to non-executable file