diff options
author | bsiegert <bsiegert@pkgsrc.org> | 2018-07-04 14:09:07 +0000 |
---|---|---|
committer | bsiegert <bsiegert@pkgsrc.org> | 2018-07-04 14:09:07 +0000 |
commit | 662696385b018ab0af47e32d98e640189df6a3aa (patch) | |
tree | e40ed1512eb8e5b0d774035e971935eb08310b6d /devel/gmake | |
parent | 3cc59ce5299d6358f3c1487cc9da3d48ef0a0647 (diff) | |
download | pkgsrc-662696385b018ab0af47e32d98e640189df6a3aa.tar.gz |
Patch SV 51159 in GNU Make.
Hopefully this will fix the problems joerg@ and others encountered last
time gmake was updated to 4.2.1. Description of the patch:
[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.
Diffstat (limited to 'devel/gmake')
-rw-r--r-- | devel/gmake/Makefile | 3 | ||||
-rw-r--r-- | devel/gmake/distinfo | 3 | ||||
-rw-r--r-- | devel/gmake/patches/patch-makeint.h | 2 | ||||
-rw-r--r-- | devel/gmake/patches/patch-posixos.c | 162 |
4 files changed, 167 insertions, 3 deletions
diff --git a/devel/gmake/Makefile b/devel/gmake/Makefile index 7a7f43ae1de..ad5f81073b6 100644 --- a/devel/gmake/Makefile +++ b/devel/gmake/Makefile @@ -1,7 +1,8 @@ -# $NetBSD: Makefile,v 1.105 2018/07/04 09:42:56 bsiegert Exp $ +# $NetBSD: Makefile,v 1.106 2018/07/04 14:09:07 bsiegert Exp $ DISTNAME= make-4.2.1 PKGNAME= g${DISTNAME} +PKGREVISION= 1 CATEGORIES= devel MASTER_SITES= ${MASTER_SITE_GNU:=make/} EXTRACT_SUFX= .tar.bz2 diff --git a/devel/gmake/distinfo b/devel/gmake/distinfo index 625b126a523..d68606958e1 100644 --- a/devel/gmake/distinfo +++ b/devel/gmake/distinfo @@ -1,4 +1,4 @@ -$NetBSD: distinfo,v 1.35 2018/07/04 09:42:56 bsiegert Exp $ +$NetBSD: distinfo,v 1.36 2018/07/04 14:09:07 bsiegert Exp $ SHA1 (make-4.2.1.tar.bz2) = 7d9d11eb36cfb752da1fb11bb3e521d2a3cc8830 RMD160 (make-4.2.1.tar.bz2) = 7cf74e2fd9764ffeb48f40a49077099874ad8a54 @@ -10,3 +10,4 @@ SHA1 (patch-configure.ac) = 7d22c8f5e5d349687885f55120fa2f7c1251e399 SHA1 (patch-dir.c) = 1616d8e26c0761c8734063806fa581ae8884b4e8 SHA1 (patch-makeint.h) = cb5f0889d84874a16fc10bc6f91e18c2277194cc SHA1 (patch-pa) = 2c0168db7afec3da98b30392290e5b9464ea7b5e +SHA1 (patch-posixos.c) = 4c566b23442bcc87f776181be531957c254162de diff --git a/devel/gmake/patches/patch-makeint.h b/devel/gmake/patches/patch-makeint.h index ef2c2ceb218..4b42e8290fe 100644 --- a/devel/gmake/patches/patch-makeint.h +++ b/devel/gmake/patches/patch-makeint.h @@ -1,4 +1,4 @@ -$NetBSD: patch-makeint.h,v 1.7 2018/07/04 09:42:56 bsiegert Exp $ +$NetBSD: patch-makeint.h,v 1.8 2018/07/04 14:09:07 bsiegert Exp $ * Do not override stack limits by default. It can dramatically increase the memory use of multi-threaded programs. diff --git a/devel/gmake/patches/patch-posixos.c b/devel/gmake/patches/patch-posixos.c new file mode 100644 index 00000000000..dc3081c203f --- /dev/null +++ b/devel/gmake/patches/patch-posixos.c @@ -0,0 +1,162 @@ +$NetBSD: patch-posixos.c,v 1.1 2018/07/04 14:09:07 bsiegert Exp $ + +http://git.savannah.gnu.org/cgit/make.git/commit/?id=b552b05251980f693c729e251f93f5225b400714 + +[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.orig 2016-05-21 20:21:52.000000000 +0000 ++++ posixos.c +@@ -59,6 +59,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) + { +@@ -78,6 +96,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; + } + +@@ -113,6 +134,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; + } + +@@ -161,7 +185,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; + +@@ -239,18 +266,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?) */ +@@ -259,28 +280,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")); ++ ++ 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")); ++ } + +- /* 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; ++ /* read() should never return 0: only the master make can reap all the ++ tokens and close the write side...?? */ ++ return r > 0; ++ } + } + + #else |