SOURCES: make-fdleak.patch (NEW), make-jobserver.patch (NEW), make-rlimit.p...

arekm arekm at pld-linux.org
Sun Feb 8 23:31:59 CET 2009


Author: arekm                        Date: Sun Feb  8 22:31:59 2009 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- from fc

---- Files affected:
SOURCES:
   make-fdleak.patch (NONE -> 1.1)  (NEW), make-jobserver.patch (NONE -> 1.1)  (NEW), make-rlimit.patch (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: SOURCES/make-fdleak.patch
diff -u /dev/null SOURCES/make-fdleak.patch:1.1
--- /dev/null	Sun Feb  8 23:32:00 2009
+++ SOURCES/make-fdleak.patch	Sun Feb  8 23:31:53 2009
@@ -0,0 +1,60 @@
+diff -urp make-3.81/read.c make-3.81-leak/read.c
+--- make-3.81/read.c	2006-03-17 15:24:20.000000000 +0100
++++ make-3.81-leak/read.c	2008-09-16 16:43:12.000000000 +0200
+@@ -296,6 +300,37 @@ restore_conditionals (struct conditional
+   conditionals = saved;
+ }
+ 
++/* If possible, open the file and mark it close-on-exec, so that make
++   doesn't leak the descriptor to binaries called via $(shell ...).*/
++static FILE *
++open_makefile (char *filename)
++{
++  FILE *fp;
++
++#if HAVE_FDOPEN
++  int fd = open (filename, O_RDONLY);
++  int save;
++  if (fd < 0)
++    return NULL;
++
++  fp = fdopen (fd, "r");
++  if (fp == NULL)
++    {
++      save = errno;
++      close (fd);
++      errno = save;
++      return NULL;
++    }
++
++  CLOSE_ON_EXEC (fd);
++
++#else
++  fp = fopen (filename, "r");
++#endif
++
++  return fp;
++}
++
+ static int
+ eval_makefile (char *filename, int flags)
+ {
+@@ -335,7 +376,8 @@ eval_makefile (char *filename, int flags
+ 	filename = expanded;
+     }
+ 
+-  ebuf.fp = fopen (filename, "r");
++  ebuf.fp = open_makefile (filename);
++
+   /* Save the error code so we print the right message later.  */
+   makefile_errno = errno;
+ 
+@@ -348,7 +390,7 @@ eval_makefile (char *filename, int flags
+       for (i = 0; include_directories[i] != 0; ++i)
+ 	{
+ 	  included = concat (include_directories[i], "/", filename);
+-	  ebuf.fp = fopen (included, "r");
++	  ebuf.fp = open_makefile (included);
+ 	  if (ebuf.fp)
+ 	    {
+ 	      filename = included;

================================================================
Index: SOURCES/make-jobserver.patch
diff -u /dev/null SOURCES/make-jobserver.patch:1.1
--- /dev/null	Sun Feb  8 23:32:00 2009
+++ SOURCES/make-jobserver.patch	Sun Feb  8 23:31:53 2009
@@ -0,0 +1,18 @@
+diff -urp make-3.81/main.c make-3.81-pm/main.c
+--- make-3.81/main.c	2007-09-24 15:28:34.000000000 +0200
++++ make-3.81-pm/main.c	2007-09-24 15:32:50.000000000 +0200
+@@ -1669,8 +1669,12 @@ main (int argc, char **argv, char **envp
+ 
+     if (job_slots > 0)
+       {
+-        close (job_fds[0]);
+-        close (job_fds[1]);
++	if (restarts == 0)
++	  {
++	    close (job_fds[0]);
++	    close (job_fds[1]);
++	  }
++
+         job_fds[0] = job_fds[1] = -1;
+         free (jobserver_fds->list);
+         free (jobserver_fds);

================================================================
Index: SOURCES/make-rlimit.patch
diff -u /dev/null SOURCES/make-rlimit.patch:1.1
--- /dev/null	Sun Feb  8 23:32:01 2009
+++ SOURCES/make-rlimit.patch	Sun Feb  8 23:31:53 2009
@@ -0,0 +1,111 @@
+diff -urp make-3.81/job.c make-3.81-pm/job.c
+--- make-3.81/job.c	2008-03-25 18:15:38.000000000 +0100
++++ make-3.81-pm/job.c	2008-03-25 17:51:11.000000000 +0100
+@@ -2079,6 +2079,9 @@ exec_command (char **argv, char **envp)
+ # else
+ 
+   /* Run the program.  */
++#ifdef SET_STACK_SIZE
++  restore_original_stack_rlimit ();
++#endif
+   environ = envp;
+   execvp (argv[0], argv);
+ 
+diff -urp make-3.81/main.c make-3.81-pm/main.c
+--- make-3.81/main.c	2008-03-25 18:15:38.000000000 +0100
++++ make-3.81-pm/main.c	2008-03-25 18:14:04.000000000 +0100
+@@ -44,12 +44,53 @@ Foundation, Inc., 51 Franklin St, Fifth 
+ # include <fcntl.h>
+ #endif
+ 
+-#if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT)
+-# define SET_STACK_SIZE
+-#endif
+-
+ #ifdef SET_STACK_SIZE
+ # include <sys/resource.h>
++/* Whether the rlimit was set successfuly */
++static int setrlimit_succeeded = 0;
++/* Original rlim_cur */
++static rlim_t setrlimit_orig_cur = 0;
++
++/* Get rid of any avoidable limit on stack size so that alloca does
++   not fail. */
++void
++set_max_stack_rlimit (void)
++{
++  struct rlimit rlim;
++
++  /* Back off if the limit is still set, probably due to failure in
++     restore_original_stack_rlimit. */
++  if (setrlimit_succeeded)
++    return;
++
++  if (getrlimit (RLIMIT_STACK, &rlim) == 0)
++    {
++      setrlimit_orig_cur = rlim.rlim_cur;
++      rlim.rlim_cur = rlim.rlim_max;
++      if (setrlimit (RLIMIT_STACK, &rlim) != -1)
++	setrlimit_succeeded = 1;
++    }
++}
++
++/* Set the rlimit back to its original value.  To be called before
++   process spawn. */
++void
++restore_original_stack_rlimit (void)
++{
++  struct rlimit rlim;
++
++  if (!setrlimit_succeeded)
++    return;
++
++  if (getrlimit (RLIMIT_STACK, &rlim) == 0)
++    {
++      rlim.rlim_cur = setrlimit_orig_cur;
++      setrlimit (RLIMIT_STACK, &rlim);
++      /* Don't reset the setrlimit_succeeded flag.  This can be called
++	 after vfork, in which case the flag is in memory shared with
++	 the parent. */
++    }
++}
+ #endif
+ 
+ #ifdef _AMIGA
+@@ -915,17 +956,7 @@ main (int argc, char **argv, char **envp
+ #endif
+ 
+ #ifdef SET_STACK_SIZE
+- /* Get rid of any avoidable limit on stack size.  */
+-  {
+-    struct rlimit rlim;
+-
+-    /* Set the stack limit huge so that alloca does not fail.  */
+-    if (getrlimit (RLIMIT_STACK, &rlim) == 0)
+-      {
+-        rlim.rlim_cur = rlim.rlim_max;
+-        setrlimit (RLIMIT_STACK, &rlim);
+-      }
+-  }
++  set_max_stack_rlimit ();
+ #endif
+ 
+ #ifdef HAVE_ATEXIT
+diff -urp make-3.81/make.h make-3.81-pm/make.h
+--- make-3.81/make.h	2008-03-25 18:15:38.000000000 +0100
++++ make-3.81-pm/make.h	2008-03-25 17:51:10.000000000 +0100
+@@ -346,6 +346,13 @@ extern int strcmpi (const char *,const c
+ #define N_(msgid)           gettext_noop (msgid)
+ #define S_(msg1,msg2,num)   ngettext (msg1,msg2,num)
+ 
++/* Handle rlimit */
++#if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT)
++# define SET_STACK_SIZE
++void set_max_stack_rlimit (void);
++void restore_original_stack_rlimit (void);
++#endif
++
+ /* Handle other OSs.  */
+ #if defined(HAVE_DOS_PATHS)
+ # define PATH_SEPARATOR_CHAR ';'
+diff -urp make-3.81/w32/Makefile make-3.81-pm/w32/Makefile
================================================================


More information about the pld-cvs-commit mailing list