summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Colin Cross <ccross@android.com> 2016-04-06 17:59:14 -0700
committer Colin Cross <ccross@android.com> 2016-04-06 17:59:14 -0700
commit8f9a53258b02083edf3044eb59515b06669b9126 (patch)
tree64f1c11eade4755ed05bd703f007852c352b46f7
parenta6a6285686a753aaedebc2edcbf94f14cb7b6fdf (diff)
makeparallel: reset make's unlimited stack
make 3.81 sets its own stack size to be unlimited, but accidentally leaves it unlimited for all child processes. If it is unlimited, reset it back to a reasonable default (8MB). See http://savannah.gnu.org/bugs/?22010 Change-Id: Ieb0289823f12a421b59d8ab5292d3df3c6dfc27e
-rw-r--r--tools/makeparallel/makeparallel.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/tools/makeparallel/makeparallel.cpp b/tools/makeparallel/makeparallel.cpp
index 3c39846ecd..c70fa9a782 100644
--- a/tools/makeparallel/makeparallel.cpp
+++ b/tools/makeparallel/makeparallel.cpp
@@ -26,6 +26,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -343,6 +344,15 @@ int main(int argc, char* argv[]) {
// child
unsetenv("MAKEFLAGS");
unsetenv("MAKELEVEL");
+
+ // make 3.81 sets the stack ulimit to unlimited, which may cause problems
+ // for child processes
+ struct rlimit rlim{};
+ if (getrlimit(RLIMIT_STACK, &rlim) == 0 && rlim.rlim_cur == RLIM_INFINITY) {
+ rlim.rlim_cur = 8*1024*1024;
+ setrlimit(RLIMIT_STACK, &rlim);
+ }
+
int ret = execvp(path, args.data());
if (ret < 0) {
error(errno, errno, "exec %s failed", path);