]>
Commit | Line | Data |
---|---|---|
ebd9bd39 MT |
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) | |
5 | # else | |
6 | ||
7 | /* Run the program. */ | |
8 | +#ifdef SET_STACK_SIZE | |
9 | + restore_original_stack_rlimit (); | |
10 | +#endif | |
11 | environ = envp; | |
12 | execvp (argv[0], argv); | |
13 | ||
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 | |
18 | # include <fcntl.h> | |
19 | #endif | |
20 | ||
21 | -#if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT) | |
22 | -# define SET_STACK_SIZE | |
23 | -#endif | |
24 | - | |
25 | #ifdef 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; | |
31 | + | |
32 | +/* Get rid of any avoidable limit on stack size so that alloca does | |
33 | + not fail. */ | |
34 | +void | |
35 | +set_max_stack_rlimit (void) | |
36 | +{ | |
37 | + struct rlimit rlim; | |
38 | + | |
39 | + /* Back off if the limit is still set, probably due to failure in | |
40 | + restore_original_stack_rlimit. */ | |
41 | + if (setrlimit_succeeded) | |
42 | + return; | |
43 | + | |
44 | + if (getrlimit (RLIMIT_STACK, &rlim) == 0) | |
45 | + { | |
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; | |
50 | + } | |
51 | +} | |
52 | + | |
53 | +/* Set the rlimit back to its original value. To be called before | |
54 | + process spawn. */ | |
55 | +void | |
56 | +restore_original_stack_rlimit (void) | |
57 | +{ | |
58 | + struct rlimit rlim; | |
59 | + | |
60 | + if (!setrlimit_succeeded) | |
61 | + return; | |
62 | + | |
63 | + if (getrlimit (RLIMIT_STACK, &rlim) == 0) | |
64 | + { | |
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 | |
69 | + the parent. */ | |
70 | + } | |
71 | +} | |
72 | #endif | |
73 | ||
74 | #ifdef _AMIGA | |
75 | @@ -915,17 +956,7 @@ main (int argc, char **argv, char **envp | |
76 | #endif | |
77 | ||
78 | #ifdef SET_STACK_SIZE | |
79 | - /* Get rid of any avoidable limit on stack size. */ | |
80 | - { | |
81 | - struct rlimit rlim; | |
82 | - | |
83 | - /* Set the stack limit huge so that alloca does not fail. */ | |
84 | - if (getrlimit (RLIMIT_STACK, &rlim) == 0) | |
85 | - { | |
86 | - rlim.rlim_cur = rlim.rlim_max; | |
87 | - setrlimit (RLIMIT_STACK, &rlim); | |
88 | - } | |
89 | - } | |
90 | + set_max_stack_rlimit (); | |
91 | #endif | |
92 | ||
93 | #ifdef HAVE_ATEXIT | |
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) | |
100 | ||
101 | +/* Handle rlimit */ | |
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); | |
106 | +#endif | |
107 | + | |
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 |