diff options
author | eldritch horrors <pennae@lix.systems> | 2024-03-06 05:45:40 +0100 |
---|---|---|
committer | eldritch horrors <pennae@lix.systems> | 2024-03-05 23:36:42 -0700 |
commit | e9b5929b22116cb714adfe88ba39a817e89b019c (patch) | |
tree | 22d9c19a56a8e713b768a23fca79496bcebe29a7 /src | |
parent | a499383187d1883e9dd688810e372462cd6e13a3 (diff) |
Merge pull request #9860 from 9999years/set-stack-darwin
Increase stack size on macOS as well as Linux
(cherry picked from commit efb91d5979a625d5c50558aeabfd24e802ed9173,
4a2444b3f32a2f5d42c4d65302793b987d1ac667)
Change-Id: Ieb72283c61bb9e360683f531d6635697b293c313
Diffstat (limited to 'src')
-rw-r--r-- | src/libutil/util.cc | 23 | ||||
-rw-r--r-- | src/libutil/util.hh | 3 |
2 files changed, 16 insertions, 10 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index baff6624c..6fcce5d67 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -1856,20 +1856,27 @@ static void restoreSignals() throw SysError("restoring signals"); } -#if __linux__ rlim_t savedStackSize = 0; -#endif -void setStackSize(size_t stackSize) +void setStackSize(rlim_t stackSize) { - #if __linux__ struct rlimit limit; if (getrlimit(RLIMIT_STACK, &limit) == 0 && limit.rlim_cur < stackSize) { savedStackSize = limit.rlim_cur; - limit.rlim_cur = stackSize; - setrlimit(RLIMIT_STACK, &limit); + limit.rlim_cur = std::min(stackSize, limit.rlim_max); + if (setrlimit(RLIMIT_STACK, &limit) != 0) { + logger->log( + lvlError, + hintfmt( + "Failed to increase stack size from %1% to %2% (maximum allowed stack size: %3%): %4%", + savedStackSize, + stackSize, + limit.rlim_max, + std::strerror(errno) + ).str() + ); + } } - #endif } #if __linux__ @@ -1930,7 +1937,6 @@ void restoreProcessContext(bool restoreMounts) restoreMountNamespace(); } - #if __linux__ if (savedStackSize) { struct rlimit limit; if (getrlimit(RLIMIT_STACK, &limit) == 0) { @@ -1938,7 +1944,6 @@ void restoreProcessContext(bool restoreMounts) setrlimit(RLIMIT_STACK, &limit); } } - #endif } /* RAII helper to automatically deregister a callback. */ diff --git a/src/libutil/util.hh b/src/libutil/util.hh index b302d6f45..bcee42327 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -8,6 +8,7 @@ #include <sys/types.h> #include <sys/stat.h> +#include <sys/resource.h> #include <dirent.h> #include <unistd.h> #include <signal.h> @@ -447,7 +448,7 @@ void runProgram2(const RunOptions & options); /** * Change the stack size. */ -void setStackSize(size_t stackSize); +void setStackSize(rlim_t stackSize); /** |