From f12a4fddce3f0475a114505a373374cf20f387e8 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Sun, 8 Dec 2024 16:27:06 -0500 Subject: [PATCH] jobserver: Ensure the named pipe is deleted on error Make sure the jobserver named pipe is deleted even if the jobserver_setup() function calls fatal() and exits early. * src/main.c (clean_jobserver): Always reset_jobserver(). * src/posixos.c (jobserver_setup): Set job_root up front. * tests/test_driver.pl: Print out the logfile pathname on error. For tests with regex matches this might be the only file available. Don't print the base filename unless one is created. --- src/main.c | 4 ++-- src/posixos.c | 5 +++-- tests/test_driver.pl | 6 ++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main.c b/src/main.c index 78084d09..6a129768 100644 --- a/src/main.c +++ b/src/main.c @@ -3826,9 +3826,9 @@ clean_jobserver (int status) ONN (error, NILF, "INTERNAL: exiting with %u jobserver tokens available; should be %u!", tokens, master_job_slots); - - reset_jobserver (); } + + reset_jobserver (); } /* Exit with STATUS, cleaning up as necessary. */ diff --git a/src/posixos.c b/src/posixos.c index 6b0b716e..163ca6ed 100644 --- a/src/posixos.c +++ b/src/posixos.c @@ -147,6 +147,9 @@ jobserver_setup (int slots, const char *style) { int r; + /* This function sets up the root jobserver. */ + job_root = 1; + #if JOBSERVER_USE_FIFO if (!style || strcmp (style, "fifo") == 0) { @@ -218,8 +221,6 @@ jobserver_setup (int slots, const char *style) /* When using pselect() we want the read to be non-blocking. */ set_blocking (job_fds[0], 0); - job_root = 1; - return 1; } diff --git a/tests/test_driver.pl b/tests/test_driver.pl index 9df598c3..810442ff 100644 --- a/tests/test_driver.pl +++ b/tests/test_driver.pl @@ -399,8 +399,9 @@ sub toplevel ++$i; print " Failure $i:\n"; print " run: $e->{'run'}\n" if exists($e->{'run'}); - print " base: $e->{'base'}\n"; + print " base: $e->{'base'}\n" if exists($e->{'base'}); print " diff: $e->{'diff'}\n" if exists($e->{'diff'}); + print " log: $e->{'log'}\n" if exists($e->{'log'}); } return 0; } @@ -1032,11 +1033,12 @@ sub compare_output my $run = get_runfile(); my $diff = get_difffile(); - my %e = ('base' => File::Spec->catdir($testpath, $base)); + my %e = ('log' => File::Spec->catdir($testpath, $logfile)); if (! $matched) { &create_file($base, $answer); &create_file($run, $command_string); + $e{'base'} = File::Spec->catdir($testpath, $base); $e{'run'} = File::Spec->catdir($testpath, $run); }