aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil/util.cc')
-rw-r--r--src/libutil/util.cc23
1 files changed, 14 insertions, 9 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. */