]> git.ipfire.org Git - thirdparty/make.git/commitdiff
Keep going if we can't connect to the jobserver
authorPaul Smith <psmith@gnu.org>
Mon, 7 Nov 2022 20:55:21 +0000 (15:55 -0500)
committerPaul Smith <psmith@gnu.org>
Sun, 13 Nov 2022 15:39:48 +0000 (10:39 -0500)
* src/posixos.c (jobserver_parse_auth): Don't invoke fatal() if we
can't connect to an existing jobserver: just keep going without it.
* src/w32/w32os.c (jobserver_parse_auth): Ditto.
* tests/scripts/features/jobserver: Add a test for invalid FIFO
auth files.

src/posixos.c
src/w32/w32os.c
tests/scripts/features/jobserver

index 44aeb3464b4ee5c25373c62ce3c0b7835c93a124..3d7d6614a77f171951569b17b6e8ddcdcbb4823f 100644 (file)
@@ -167,12 +167,12 @@ jobserver_setup (int slots, const char *style)
              hang until the write side is open.  */
           EINTRLOOP (job_fds[0], open (fifo_name, O_RDONLY|O_NONBLOCK));
           if (job_fds[0] < 0)
-            OSS (fatal, NILF, _("Cannot open jobserver %s: %s"),
+            OSS (fatal, NILF, _("cannot open jobserver %s: %s"),
                  fifo_name, strerror (errno));
 
           EINTRLOOP (job_fds[1], open (fifo_name, O_WRONLY));
           if (job_fds[0] < 0)
-            OSS (fatal, NILF, _("Cannot open jobserver %s: %s"),
+            OSS (fatal, NILF, _("cannot open jobserver %s: %s"),
                  fifo_name, strerror (errno));
 
           js_type = js_fifo;
@@ -183,7 +183,7 @@ jobserver_setup (int slots, const char *style)
   if (js_type == js_none)
     {
       if (style && strcmp (style, "pipe") != 0)
-        OS (fatal, NILF, _("Unknown jobserver auth style '%s'"), style);
+        OS (fatal, NILF, _("unknown jobserver auth style '%s'"), style);
 
       EINTRLOOP (r, pipe (job_fds));
       if (r < 0)
@@ -229,14 +229,19 @@ jobserver_parse_auth (const char *auth)
 
       EINTRLOOP (job_fds[0], open (fifo_name, O_RDONLY));
       if (job_fds[0] < 0)
-        OSS (fatal, NILF,
-             _("Cannot open jobserver %s: %s"), fifo_name, strerror (errno));
+        {
+          OSS (error, NILF,
+               _("cannot open jobserver %s: %s"), fifo_name, strerror (errno));
+          return 0;
+        }
 
       EINTRLOOP (job_fds[1], open (fifo_name, O_WRONLY));
-      if (job_fds[0] < 0)
-        OSS (fatal, NILF,
-             _("Cannot open jobserver %s: %s"), fifo_name, strerror (errno));
-
+      if (job_fds[1] < 0)
+        {
+          OSS (error, NILF,
+               _("cannot open jobserver %s: %s"), fifo_name, strerror (errno));
+          return 0;
+        }
       js_type = js_fifo;
     }
   /* If not, it must be a simple pipe.  */
index 9c5dec247815594f2ac49dfa7d3a89ddf0f89759..213bbf1244a9eea2f0859539f1f0a867aaceb346 100644 (file)
@@ -216,12 +216,12 @@ jobserver_setup (int slots, const char *style)
   /* sub_proc.c is limited in the number of objects it can wait for. */
 
   if (style && strcmp (style, "sem") != 0)
-    OS (fatal, NILF, _("Unknown jobserver auth style '%s'"), style);
+    OS (fatal, NILF, _("unknown jobserver auth style '%s'"), style);
 
   if (slots > process_table_usable_size())
     {
       slots = process_table_usable_size();
-      DB (DB_JOBS, (_("Jobserver slots limited to %d\n"), slots));
+      DB (DB_JOBS, (_("jobserver slots limited to %d\n"), slots));
     }
 
   sprintf (jobserver_semaphore_name, "gmake_semaphore_%d", _getpid ());
@@ -255,10 +255,12 @@ jobserver_parse_auth (const char *auth)
     {
       DWORD err = GetLastError ();
       const char *estr = map_windows32_error_to_string (err);
-      fatal (NILF, strlen (auth) + INTSTR_LENGTH + strlen (estr),
-             _("internal error: unable to open jobserver semaphore '%s': (Error %ld: %s)"),
+      error (NILF, strlen (auth) + INTSTR_LENGTH + strlen (estr),
+             _("unable to open jobserver semaphore '%s': (Error %ld: %s)"),
              auth, err, estr);
+      return 0;
     }
+
   DB (DB_JOBS, (_("Jobserver client (semaphore %s)\n"), auth));
 
   return 1;
index 8ecbe3458a6b18f625c5d40fb195829d8feab0c5..e12facf0ae4a480ac409c8dd745f3a910225144b 100644 (file)
@@ -14,6 +14,7 @@ if (!$parallel_jobs) {
 
 # Shorthand
 my $np = '--no-print-directory';
+my $j1err = "warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.";
 
 # Simple test of MAKEFLAGS settings
 run_make_test(q!
@@ -90,7 +91,7 @@ if ($port_type ne 'W32') {
 default: ; @ #MAKEPATH# -f Makefile2
 !,
               "--jobserver-style=pipe -j2 $np",
-"#MAKE#[1]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
+"#MAKE#[1]: $j1err
 #MAKE#[1]: Nothing to be done for 'foo'.");
 
     rmfiles('Makefile2');
@@ -98,15 +99,15 @@ default: ; @ #MAKEPATH# -f Makefile2
 
 # For Windows and named pipes, we don't need to worry about recursion
 if ($port_type eq 'W32' || exists $FEATURES{'jobserver-fifo'}) {
-    create_file('Makefile2', "vpath %.c ../\n", "foo:\n");
+  create_file('Makefile2', "vpath %.c ../\n", "foo:\n");
 
-    run_make_test(q!
+  run_make_test(q!
 default: ; @ #MAKEPATH# -f Makefile2
 !,
               "-j2 $np",
 "#MAKE#[1]: Nothing to be done for 'foo'.");
 
-    rmfiles('Makefile2');
+  rmfiles('Makefile2');
 }
 
 # Ensure enter/leave directory messages appear before jobserver warnings
@@ -129,17 +130,17 @@ all: a
 all a: ; @echo $@
 !,
               '--jobserver-style=foo -j8',
-              "#MAKE#: *** Unknown jobserver auth style 'foo'.  Stop.", 512);
-
-# sv 62908.
-# Test that when mkfifo fails, make switches to pipe and succeeds.
-# Force mkfifo to fail by attempting to create a fifo in a non existent
-# directory.
-# run_make_test does not allow matching a multiline pattern, therefore run the
-# test twice.
-# First time look for /$ERR_no_such_file/ to ensure mkfifo failed.
-# Second time look for /Nothing to be done/ to ensure make succeeded.
+              "#MAKE#: *** unknown jobserver auth style 'foo'.  Stop.", 512);
+
 if (exists $FEATURES{'jobserver-fifo'}) {
+  # sv 62908.
+  # Test that when mkfifo fails, make switches to pipe and succeeds.
+  # Force mkfifo to fail by attempting to create a fifo in a non existent
+  # directory.
+  # run_make_test does not allow matching a multiline pattern, therefore run
+  # the test twice.
+  # First time look for /$ERR_no_such_file/ to ensure mkfifo failed.
+  # Second time look for /Nothing to be done/ to ensure make succeeded.
   $ENV{TMPDIR} = "nosuchdir";
   run_make_test("all:\n", '-j2', "/$ERR_no_such_file/");
 
@@ -155,6 +156,10 @@ recurse: ; @$(MAKE) -f #MAKEFILE# all
 all:;@echo "$$MAKEFLAGS"
 !,
               "-j2 --no-print-directory", "/--jobserver-auth=fifo:\\./");
+
+  # Verify we fall back to -j1 but continue, of the auth is bad.
+  $ENV{MAKEFLAGS} = '-j2 --jobserver-auth=fifo:nosuchfile';
+  run_make_test(q!all:;@echo hi!, "", "#MAKE#: cannot open jobserver nosuchfile: $ERR_no_such_file\n#MAKE#: $j1err\nhi\n");
 }
 
 1;