pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/devel/gmake Patch SV 51159 in GNU Make.



details:   https://anonhg.NetBSD.org/pkgsrc/rev/cc39ca8ef514
branches:  trunk
changeset: 310068:cc39ca8ef514
user:      bsiegert <bsiegert%pkgsrc.org@localhost>
date:      Wed Jul 04 14:09:07 2018 +0000

description:
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:

 devel/gmake/Makefile                |    3 +-
 devel/gmake/distinfo                |    3 +-
 devel/gmake/patches/patch-makeint.h |    2 +-
 devel/gmake/patches/patch-posixos.c |  162 ++++++++++++++++++++++++++++++++++++
 4 files changed, 167 insertions(+), 3 deletions(-)

diffs (202 lines):

diff -r a098ff6ac79a -r cc39ca8ef514 devel/gmake/Makefile
--- a/devel/gmake/Makefile      Wed Jul 04 13:40:07 2018 +0000
+++ b/devel/gmake/Makefile      Wed Jul 04 14:09:07 2018 +0000
@@ -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 -r a098ff6ac79a -r cc39ca8ef514 devel/gmake/distinfo
--- a/devel/gmake/distinfo      Wed Jul 04 13:40:07 2018 +0000
+++ b/devel/gmake/distinfo      Wed Jul 04 14:09:07 2018 +0000
@@ -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-dir.c) = 1616d8e26c0761c8734063806fa581ae8884b4e8
 SHA1 (patch-makeint.h) = cb5f0889d84874a16fc10bc6f91e18c2277194cc
 SHA1 (patch-pa) = 2c0168db7afec3da98b30392290e5b9464ea7b5e
+SHA1 (patch-posixos.c) = 4c566b23442bcc87f776181be531957c254162de
diff -r a098ff6ac79a -r cc39ca8ef514 devel/gmake/patches/patch-makeint.h
--- a/devel/gmake/patches/patch-makeint.h       Wed Jul 04 13:40:07 2018 +0000
+++ b/devel/gmake/patches/patch-makeint.h       Wed Jul 04 14:09:07 2018 +0000
@@ -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 -r a098ff6ac79a -r cc39ca8ef514 devel/gmake/patches/patch-posixos.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/devel/gmake/patches/patch-posixos.c       Wed Jul 04 14:09:07 2018 +0000
@@ -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



Home | Main Index | Thread Index | Old Index