1 diff -urp make-3.81/job.c make-3.81-pm/job.c
2 --- make-3.81/job.c 2008-03-25 18:15:38.000000000 +0100
3 +++ make-3.81-pm/job.c 2008-03-25 17:51:11.000000000 +0100
4 @@ -2079,6 +2079,9 @@ exec_command (char **argv, char **envp)
9 + restore_original_stack_rlimit ();
12 execvp (argv[0], argv);
14 diff -urp make-3.81/main.c make-3.81-pm/main.c
15 --- make-3.81/main.c 2008-03-25 18:15:38.000000000 +0100
16 +++ make-3.81-pm/main.c 2008-03-25 18:14:04.000000000 +0100
17 @@ -44,12 +44,53 @@ Foundation, Inc., 51 Franklin St, Fifth
21 -#if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT)
22 -# define SET_STACK_SIZE
26 # include <sys/resource.h>
27 +/* Whether the rlimit was set successfuly */
28 +static int setrlimit_succeeded = 0;
29 +/* Original rlim_cur */
30 +static rlim_t setrlimit_orig_cur = 0;
32 +/* Get rid of any avoidable limit on stack size so that alloca does
35 +set_max_stack_rlimit (void)
39 + /* Back off if the limit is still set, probably due to failure in
40 + restore_original_stack_rlimit. */
41 + if (setrlimit_succeeded)
44 + if (getrlimit (RLIMIT_STACK, &rlim) == 0)
46 + setrlimit_orig_cur = rlim.rlim_cur;
47 + rlim.rlim_cur = rlim.rlim_max;
48 + if (setrlimit (RLIMIT_STACK, &rlim) != -1)
49 + setrlimit_succeeded = 1;
53 +/* Set the rlimit back to its original value. To be called before
56 +restore_original_stack_rlimit (void)
60 + if (!setrlimit_succeeded)
63 + if (getrlimit (RLIMIT_STACK, &rlim) == 0)
65 + rlim.rlim_cur = setrlimit_orig_cur;
66 + setrlimit (RLIMIT_STACK, &rlim);
67 + /* Don't reset the setrlimit_succeeded flag. This can be called
68 + after vfork, in which case the flag is in memory shared with
75 @@ -915,17 +956,7 @@ main (int argc, char **argv, char **envp
79 - /* Get rid of any avoidable limit on stack size. */
83 - /* Set the stack limit huge so that alloca does not fail. */
84 - if (getrlimit (RLIMIT_STACK, &rlim) == 0)
86 - rlim.rlim_cur = rlim.rlim_max;
87 - setrlimit (RLIMIT_STACK, &rlim);
90 + set_max_stack_rlimit ();
94 diff -urp make-3.81/make.h make-3.81-pm/make.h
95 --- make-3.81/make.h 2008-03-25 18:15:38.000000000 +0100
96 +++ make-3.81-pm/make.h 2008-03-25 17:51:10.000000000 +0100
97 @@ -346,6 +346,13 @@ extern int strcmpi (const char *,const c
98 #define N_(msgid) gettext_noop (msgid)
99 #define S_(msg1,msg2,num) ngettext (msg1,msg2,num)
102 +#if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT)
103 +# define SET_STACK_SIZE
104 +void set_max_stack_rlimit (void);
105 +void restore_original_stack_rlimit (void);
108 /* Handle other OSs. */
109 #if defined(HAVE_DOS_PATHS)
110 # define PATH_SEPARATOR_CHAR ';'
111 diff -urp make-3.81/w32/Makefile make-3.81-pm/w32/Makefile