From 6eb0d1205b74c6e4e5b6734bde24dd0774e461ef Mon Sep 17 00:00:00 2001 From: Christian Wiese Date: Thu, 15 Jul 2010 14:55:29 +0200 Subject: [PATCH] make: fixed stack limit bug (upstream fix) bug #22010: The increased stack rlimit is inherited by the subprocesses to make. http://savannah.gnu.org/bugs/?22010 http://cvs.savannah.gnu.org/viewvc/make/make.h?root=make&r1=1.132&r2=1.133&view=patch http://cvs.savannah.gnu.org/viewvc/make/main.c?root=make&r1=1.228&r2=1.229&view=patch http://cvs.savannah.gnu.org/viewvc/make/job.c?root=make&r1=1.191&r2=1.192&view=patch 2009-06-07 Paul Smith * make.h: Move SET_STACK_SIZE determination to make.h. * main.c (main): New global variable, STACK_LIMIT, holds the original stack limit when make was started. * job.c (start_job_command): Reset the stack limit, if we changed it. Fixes Savannah bug #22010. --- base/make/0002-fix-stack-limit.patch | 127 +++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 base/make/0002-fix-stack-limit.patch diff --git a/base/make/0002-fix-stack-limit.patch b/base/make/0002-fix-stack-limit.patch new file mode 100644 index 000000000..a15d771aa --- /dev/null +++ b/base/make/0002-fix-stack-limit.patch @@ -0,0 +1,127 @@ +# --- SDE-COPYRIGHT-NOTE-BEGIN --- +# This copyright note is auto-generated by ./scripts/Create-CopyPatch. +# +# Filename: package/.../make/0002-fix-stack-limit.patch +# Copyright (C) 2010 The OpenSDE Project +# +# More information can be found in the files COPYING and README. +# +# This patch file is dual-licensed. It is available under the license the +# patched project is licensed under, as long as it is an OpenSource license +# as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms +# of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# --- SDE-COPYRIGHT-NOTE-END --- + +bug #22010: The increased stack rlimit is inherited by the subprocesses to make. +http://savannah.gnu.org/bugs/?22010 +http://cvs.savannah.gnu.org/viewvc/make/make.h?root=make&r1=1.132&r2=1.133&view=patch +http://cvs.savannah.gnu.org/viewvc/make/main.c?root=make&r1=1.228&r2=1.229&view=patch +http://cvs.savannah.gnu.org/viewvc/make/job.c?root=make&r1=1.191&r2=1.192&view=patch + +2009-06-07 Paul Smith + * make.h: Move SET_STACK_SIZE determination to make.h. + * main.c (main): New global variable, STACK_LIMIT, holds the + original stack limit when make was started. + * job.c (start_job_command): Reset the stack limit, if we changed it. + Fixes Savannah bug #22010. + +diff --git a/job.c b/job.c +index 3251efe..7fe08fa 100644 +--- a/job.c ++++ b/job.c +@@ -1275,6 +1275,12 @@ start_job_command (struct child *child) + if (job_rfd >= 0) + close (job_rfd); + ++#ifdef SET_STACK_SIZE ++ /* Reset limits, if necessary. */ ++ if (stack_limit.rlim_cur) ++ setrlimit (RLIMIT_STACK, &stack_limit); ++#endif ++ + child_execute_job (child->good_stdin ? 0 : bad_stdin, 1, + argv, child->environment); + } +@@ -2237,7 +2243,7 @@ construct_command_argv_internal (char *line, char **restp, char *shell, + "for", "case", "if", ":", ".", "break", + "continue", "export", "read", "readonly", + "shift", "times", "trap", "switch", "unset", +- 0 }; ++ "ulimit", 0 }; + + char *sh_chars; + char **sh_cmds; +diff --git a/main.c b/main.c +index 483babf..42964e0 100644 +--- a/main.c ++++ b/main.c +@@ -44,14 +44,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ + # include + #endif + +-#if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT) +-# define SET_STACK_SIZE +-#endif +- +-#ifdef SET_STACK_SIZE +-# include +-#endif +- + #ifdef _AMIGA + int __stack = 20000; /* Make sure we have 20K of stack space */ + #endif +@@ -213,6 +205,13 @@ int print_version_flag = 0; + + static struct stringlist *makefiles = 0; + ++/* Size of the stack when we started. */ ++ ++#ifdef SET_STACK_SIZE ++struct rlimit stack_limit; ++#endif ++ ++ + /* Number of job slots (commands that can be run at once). */ + + unsigned int job_slots = 1; +@@ -919,11 +918,15 @@ main (int argc, char **argv, char **envp) + struct rlimit rlim; + + /* Set the stack limit huge so that alloca does not fail. */ +- if (getrlimit (RLIMIT_STACK, &rlim) == 0) ++ if (getrlimit (RLIMIT_STACK, &rlim) == 0 ++ && rlim.rlim_cur > 0 && rlim.rlim_cur < rlim.rlim_max) + { ++ stack_limit = rlim; + rlim.rlim_cur = rlim.rlim_max; + setrlimit (RLIMIT_STACK, &rlim); + } ++ else ++ stack_limit.rlim_cur = 0; + } + #endif + +diff --git a/make.h b/make.h +index 994f4f2..25c2bef 100644 +--- a/make.h ++++ b/make.h +@@ -378,6 +378,14 @@ extern int no_default_sh_exe; + extern int unixy_shell; + #endif /* WINDOWS32 */ + ++#if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT) ++# define SET_STACK_SIZE ++#endif ++#ifdef SET_STACK_SIZE ++# include ++struct rlimit stack_limit; ++#endif ++ + struct floc + { + const char *filenm; +-- +1.6.5.3 +