aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Compositor.cpp
diff options
context:
space:
mode:
authorVaxry <[email protected]>2024-06-19 18:36:40 +0200
committerVaxry <[email protected]>2024-06-19 18:36:40 +0200
commitc1e21719a2fff2fa9549f00053ac40173da54af9 (patch)
treefca9aaedfd119c14b10a8bff8b3c5f5c448aef50 /src/Compositor.cpp
parentdef5fcb2128304392e9e76bcc081d088b316a197 (diff)
downloadHyprland-c1e21719a2fff2fa9549f00053ac40173da54af9.tar.gz
Hyprland-c1e21719a2fff2fa9549f00053ac40173da54af9.zip
core: avoid bumping hard rlimits, restore on fork
ref #6584
Diffstat (limited to 'src/Compositor.cpp')
-rw-r--r--src/Compositor.cpp55
1 files changed, 23 insertions, 32 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp
index 7777a55f..7a1d035d 100644
--- a/src/Compositor.cpp
+++ b/src/Compositor.cpp
@@ -71,44 +71,35 @@ void handleUserSignal(int sig) {
}
}
-static void bumpNofile() {
- unsigned long limit = 1024;
-
- try {
- std::ifstream f("/proc/sys/fs/nr_open");
- if (!f.good())
- limit = 1073741816;
- else {
- std::string content((std::istreambuf_iterator<char>(f)), (std::istreambuf_iterator<char>()));
- f.close();
-
- limit = std::stoll(content);
- }
-
- } catch (...) { limit = 1073741816; }
-
- struct rlimit rlimit_;
- if (!getrlimit(RLIMIT_NOFILE, &rlimit_))
- Debug::log(LOG, "Old rlimit: soft -> {}, hard -> {}", rlimit_.rlim_cur, rlimit_.rlim_max);
+void CCompositor::bumpNofile() {
+ if (!getrlimit(RLIMIT_NOFILE, &m_sOriginalNofile))
+ Debug::log(LOG, "Old rlimit: soft -> {}, hard -> {}", m_sOriginalNofile.rlim_cur, m_sOriginalNofile.rlim_max);
+ else {
+ Debug::log(ERR, "Failed to get NOFILE rlimits");
+ m_sOriginalNofile.rlim_max = 0;
+ return;
+ }
- if (rlimit_.rlim_max <= 1024)
- rlimit_.rlim_max = limit;
+ rlimit newLimit = m_sOriginalNofile;
- unsigned long oldHardLimit = rlimit_.rlim_max;
+ newLimit.rlim_cur = newLimit.rlim_max;
- rlimit_.rlim_max = limit;
+ if (setrlimit(RLIMIT_NOFILE, &newLimit) < 0) {
+ Debug::log(ERR, "Failed bumping NOFILE limits higher");
+ m_sOriginalNofile.rlim_max = 0;
+ return;
+ }
- if (setrlimit(RLIMIT_NOFILE, &rlimit_) < 0) {
- Debug::log(LOG, "Failed bumping NOFILE limits higher, retrying with previous hard.");
- rlimit_.rlim_max = oldHardLimit;
- rlimit_.rlim_cur = std::clamp((unsigned long)limit, 1UL, (unsigned long)rlimit_.rlim_max);
+ if (!getrlimit(RLIMIT_NOFILE, &newLimit))
+ Debug::log(LOG, "New rlimit: soft -> {}, hard -> {}", newLimit.rlim_cur, newLimit.rlim_max);
+}
- if (setrlimit(RLIMIT_NOFILE, &rlimit_) < 0)
- Debug::log(LOG, "Failed bumping NOFILE limits higher for the second time.");
- }
+void CCompositor::restoreNofile() {
+ if (m_sOriginalNofile.rlim_max <= 0)
+ return;
- if (!getrlimit(RLIMIT_NOFILE, &rlimit_))
- Debug::log(LOG, "New rlimit: soft -> {}, hard -> {}", rlimit_.rlim_cur, rlimit_.rlim_max);
+ if (setrlimit(RLIMIT_NOFILE, &m_sOriginalNofile) < 0)
+ Debug::log(ERR, "Failed restoring NOFILE limits");
}
CCompositor::CCompositor() {