summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Deutschmann <whissi@gentoo.org>2018-08-27 21:48:25 +0200
committerThomas Deutschmann <whissi@gentoo.org>2018-08-27 21:48:25 +0200
commitb44bbe136afc2747df3f213467dd930c44454408 (patch)
tree4c589b1df3126c66f302d4301393fb319009cb0d
parentapp-editors/neovim: version bump. (diff)
downloadgentoo-b44bbe136afc2747df3f213467dd930c44454408.tar.gz
gentoo-b44bbe136afc2747df3f213467dd930c44454408.tar.bz2
gentoo-b44bbe136afc2747df3f213467dd930c44454408.zip
sys-devel/make: Use a non-blocking read with pselect to avoid hangs
Closes: https://bugs.gentoo.org/664632 Package-Manager: Portage-2.3.48, Repoman-2.3.10
-rw-r--r--sys-devel/make/files/make-4.2.1-pselect-non-blocking.patch172
-rw-r--r--sys-devel/make/make-4.2.1-r4.ebuild59
2 files changed, 231 insertions, 0 deletions
diff --git a/sys-devel/make/files/make-4.2.1-pselect-non-blocking.patch b/sys-devel/make/files/make-4.2.1-pselect-non-blocking.patch
new file mode 100644
index 000000000000..61e19516f3c3
--- /dev/null
+++ b/sys-devel/make/files/make-4.2.1-pselect-non-blocking.patch
@@ -0,0 +1,172 @@
+https://bugs.gentoo.org/664632
+
+From b552b05251980f693c729e251f93f5225b400714 Mon Sep 17 00:00:00 2001
+From: Paul Smith <psmith@gnu.org>
+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.
+---
+ posixos.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++-----------------
+ 1 file changed, 71 insertions(+), 26 deletions(-)
+
+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
+--
+cgit v1.0-41-gc330
+
diff --git a/sys-devel/make/make-4.2.1-r4.ebuild b/sys-devel/make/make-4.2.1-r4.ebuild
new file mode 100644
index 000000000000..fbc399d853b2
--- /dev/null
+++ b/sys-devel/make/make-4.2.1-r4.ebuild
@@ -0,0 +1,59 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI="6"
+
+inherit flag-o-matic
+
+DESCRIPTION="Standard tool to compile source trees"
+HOMEPAGE="https://www.gnu.org/software/make/make.html"
+SRC_URI="mirror://gnu//make/${P}.tar.bz2"
+
+LICENSE="GPL-3+"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~ppc-aix ~x64-cygwin ~amd64-fbsd ~x86-fbsd ~amd64-linux ~arm-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
+IUSE="guile nls static"
+
+CDEPEND="guile? ( >=dev-scheme/guile-1.8:= )"
+DEPEND="${CDEPEND}
+ nls? ( sys-devel/gettext )"
+RDEPEND="${CDEPEND}
+ nls? ( virtual/libintl )"
+
+PATCHES=(
+ "${FILESDIR}"/${PN}-3.82-darwin-library_search-dylib.patch
+ "${FILESDIR}"/${PN}-4.2-default-cxx.patch
+ "${FILESDIR}"/${PN}-4.2.1-perl526.patch
+ "${FILESDIR}"/${PN}-4.2.1-glob-internals.patch
+ "${FILESDIR}"/${PN}-4.2.1-pselect-non-blocking.patch
+)
+
+src_prepare() {
+ default
+ # These patches require special handling as they modify configure.ac
+ # which in turn triggers maintainer-mode when being applied the
+ # usual way.
+ eapply -Z "${FILESDIR}"/${PN}-4.2.1-glob-v2.patch \
+ "${FILESDIR}"/${P}-guile-2.2.patch
+}
+
+src_configure() {
+ use static && append-ldflags -static
+ local myeconfargs=(
+ --program-prefix=g
+ $(use_with guile)
+ $(use_enable nls)
+ )
+ econf "${myeconfargs[@]}"
+}
+
+src_install() {
+ emake DESTDIR="${D}" install
+ dodoc AUTHORS NEWS README*
+ if [[ ${USERLAND} == "GNU" ]] ; then
+ # we install everywhere as 'gmake' but on GNU systems,
+ # symlink 'make' to 'gmake'
+ dosym gmake /usr/bin/make
+ dosym gmake.1 /usr/share/man/man1/make.1
+ fi
+}