diff --git a/SOURCES/make-4.2.1-nonblocking-reads.patch b/SOURCES/make-4.2.1-nonblocking-reads.patch new file mode 100644 index 0000000..76b9545 --- /dev/null +++ b/SOURCES/make-4.2.1-nonblocking-reads.patch @@ -0,0 +1,164 @@ +From b552b05251980f693c729e251f93f5225b400714 Mon Sep 17 00:00:00 2001 +From: Paul Smith +Date: Sat, 3 Jun 2017 16:20:51 -0400 +Subject: [SV 51159] Use a non-blocking read with pselect to avoid hangs. + +* posixos.c (set_blocking): Set blocking on a file descriptor. +(jobserver_setup): Set non-blocking on the jobserver read side. +(jobserver_parse_auth): Ditto. +(jobserver_acquire_all): Set blocking to avoid a busy-wait loop. +(jobserver_acquire): If the non-blocking read() returns without +taking a token then try again. + +diff --git a/posixos.c b/posixos.c +index e642d7f..dbafa51 100644 +--- a/posixos.c ++++ b/posixos.c +@@ -62,6 +62,24 @@ make_job_rfd (void) + #endif + } + ++static void ++set_blocking (int fd, int blocking) ++{ ++ // If we're not using pselect() don't change the blocking ++#ifdef HAVE_PSELECT ++ int flags; ++ EINTRLOOP (flags, fcntl (fd, F_GETFL)); ++ if (flags >= 0) ++ { ++ int r; ++ flags = blocking ? (flags & ~O_NONBLOCK) : (flags | O_NONBLOCK); ++ EINTRLOOP (r, fcntl (fd, F_SETFL, flags)); ++ if (r < 0) ++ pfatal_with_name ("fcntl(O_NONBLOCK)"); ++ } ++#endif ++} ++ + unsigned int + jobserver_setup (int slots) + { +@@ -86,6 +104,9 @@ jobserver_setup (int slots) + pfatal_with_name (_("init jobserver pipe")); + } + ++ /* When using pselect() we want the read to be non-blocking. */ ++ set_blocking (job_fds[0], 0); ++ + return 1; + } + +@@ -121,6 +142,9 @@ jobserver_parse_auth (const char *auth) + return 0; + } + ++ /* When using pselect() we want the read to be non-blocking. */ ++ set_blocking (job_fds[0], 0); ++ + return 1; + } + +@@ -169,7 +193,10 @@ jobserver_acquire_all (void) + { + unsigned int tokens = 0; + +- /* Close the write side, so the read() won't hang. */ ++ /* Use blocking reads to wait for all outstanding jobs. */ ++ set_blocking (job_fds[0], 1); ++ ++ /* Close the write side, so the read() won't hang forever. */ + close (job_fds[1]); + job_fds[1] = -1; + +@@ -236,18 +263,12 @@ jobserver_pre_acquire (void) + unsigned int + jobserver_acquire (int timeout) + { +- sigset_t empty; +- fd_set readfds; + struct timespec spec; + struct timespec *specp = NULL; +- int r; +- char intake; ++ sigset_t empty; + + sigemptyset (&empty); + +- FD_ZERO (&readfds); +- FD_SET (job_fds[0], &readfds); +- + if (timeout) + { + /* Alarm after one second (is this too granular?) */ +@@ -256,28 +277,52 @@ jobserver_acquire (int timeout) + specp = &spec; + } + +- r = pselect (job_fds[0]+1, &readfds, NULL, NULL, specp, &empty); +- +- if (r == -1) ++ while (1) + { +- /* Better be SIGCHLD. */ +- if (errno != EINTR) +- pfatal_with_name (_("pselect jobs pipe")); +- return 0; +- } ++ fd_set readfds; ++ int r; ++ char intake; + +- if (r == 0) +- /* Timeout. */ +- return 0; ++ FD_ZERO (&readfds); ++ FD_SET (job_fds[0], &readfds); + +- /* The read FD is ready: read it! */ +- EINTRLOOP (r, read (job_fds[0], &intake, 1)); +- if (r < 0) +- pfatal_with_name (_("read jobs pipe")); ++ r = pselect (job_fds[0]+1, &readfds, NULL, NULL, specp, &empty); ++ if (r < 0) ++ switch (errno) ++ { ++ case EINTR: ++ /* SIGCHLD will show up as an EINTR. */ ++ return 0; ++ ++ case EBADF: ++ /* Someone closed the jobs pipe. ++ That shouldn't happen but if it does we're done. */ ++ O (fatal, NILF, _("job server shut down")); + +- /* What does it mean if read() returns 0? It shouldn't happen because only +- the master make can reap all the tokens and close the write side...?? */ +- return r > 0; ++ default: ++ pfatal_with_name (_("pselect jobs pipe")); ++ } ++ ++ if (r == 0) ++ /* Timeout. */ ++ return 0; ++ ++ /* The read FD is ready: read it! This is non-blocking. */ ++ EINTRLOOP (r, read (job_fds[0], &intake, 1)); ++ ++ if (r < 0) ++ { ++ /* Someone sniped our token! Try again. */ ++ if (errno == EAGAIN) ++ continue; ++ ++ pfatal_with_name (_("read jobs pipe")); ++ } ++ ++ /* read() should never return 0: only the master make can reap all the ++ tokens and close the write side...?? */ ++ return r > 0; ++ } + } + + #else diff --git a/SPECS/make.spec b/SPECS/make.spec index 7f10098..30700b8 100644 --- a/SPECS/make.spec +++ b/SPECS/make.spec @@ -4,7 +4,7 @@ Summary: A GNU tool which simplifies the build process for users Name: %{?scl_prefix}make Epoch: 1 Version: 4.2.1 -Release: 1%{?dist} +Release: 2%{?dist} License: GPLv2+ Group: Development/Tools URL: http://www.gnu.org/software/make/ @@ -25,6 +25,10 @@ Patch6: make-4.2-warn_undefined_function.patch # http://lists.gnu.org/archive/html/bug-make/2011-06/msg00032.html Patch7: make-4.2-trace.patch +# Upstream patch: https://git.savannah.gnu.org/cgit/make.git/commit/?id=b552b05251980f693c729e251f93f5225b400714 +# Avoids hangs in parallel builds +Patch8: make-4.2.1-nonblocking-reads.patch + # Buildroot: %(mktemp -ud %{_tmppath}/make-%{version}-%{release}-XXXXXX) BuildRoot: %{_tmppath}/make-%{version}-%{release}-root-%(%{__id_u} -n) Requires(post): /sbin/install-info @@ -51,6 +55,7 @@ echo "STARTING PREP of make" %patch5 -p1 %patch6 -p1 %patch7 -p1 +%patch8 -p1 rm -f tests/scripts/features/parallelism.orig @@ -101,6 +106,9 @@ fi %{_includedir}/gnumake.h %changelog +* Fri Jan 10 2020 DJ Delorie - 1:4.2.1-2 +- Use a non-blocking read with pselect to avoid hangs. BZ #1785447 + * Mon Aug 5 2019 DJ Delorie - 4.2.1-1 - Reset to -1 for devtoolset-9 (#1736673)