1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 12:06:01 +01:00

setStackSize: Warn when the desired stack size can't be set

This commit is contained in:
Robert Hensing 2025-10-15 22:40:31 +02:00
parent f6aeca0522
commit 2349c3dbde

View file

@ -65,6 +65,16 @@ void setStackSize(size_t stackSize)
struct rlimit limit; struct rlimit limit;
if (getrlimit(RLIMIT_STACK, &limit) == 0 && static_cast<size_t>(limit.rlim_cur) < stackSize) { if (getrlimit(RLIMIT_STACK, &limit) == 0 && static_cast<size_t>(limit.rlim_cur) < stackSize) {
savedStackSize = limit.rlim_cur; savedStackSize = limit.rlim_cur;
if (limit.rlim_max < static_cast<rlim_t>(stackSize)) {
logger->log(
lvlWarn,
HintFmt(
"Stack size hard limit is %1%, which is less than the desired %2%. If possible, increase the hard limit, e.g. with 'ulimit -Hs %3%'.",
limit.rlim_max,
stackSize,
stackSize / 1024)
.str());
}
auto requestedSize = std::min(static_cast<rlim_t>(stackSize), limit.rlim_max); auto requestedSize = std::min(static_cast<rlim_t>(stackSize), limit.rlim_max);
limit.rlim_cur = requestedSize; limit.rlim_cur = requestedSize;
if (setrlimit(RLIMIT_STACK, &limit) != 0) { if (setrlimit(RLIMIT_STACK, &limit) != 0) {