diff options
author | Simon Ser <contact@emersion.fr> | 2021-10-21 21:52:17 +0200 |
---|---|---|
committer | Simon Zeni <simon@bl4ckb0ne.ca> | 2021-10-30 08:19:35 -0600 |
commit | 38020d157ddb58e756c654e9a2ff203c1562b25b (patch) | |
tree | e042c3c6d0d9f03e75812dffc0ac2e54d9b6dd8e /sway/main.c | |
parent | Add smart_gaps inverse_outer command (diff) | |
download | sway-38020d157ddb58e756c654e9a2ff203c1562b25b.tar.gz sway-38020d157ddb58e756c654e9a2ff203c1562b25b.tar.zst sway-38020d157ddb58e756c654e9a2ff203c1562b25b.zip |
Bump RLIMIT_NOFILE
Wayland compositors handle many file descriptors: client
connections, DMA-BUFs, sync_files, wl_data_device pipes, and so
on. Bump the limit to the max.
Closes: https://github.com/swaywm/sway/issues/6285
Diffstat (limited to 'sway/main.c')
-rw-r--r-- | sway/main.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/sway/main.c b/sway/main.c index 264fa847..2c760524 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <stdio.h> | 6 | #include <stdio.h> |
7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
8 | #include <string.h> | 8 | #include <string.h> |
9 | #include <sys/resource.h> | ||
9 | #include <sys/stat.h> | 10 | #include <sys/stat.h> |
10 | #include <sys/types.h> | 11 | #include <sys/types.h> |
11 | #include <sys/wait.h> | 12 | #include <sys/wait.h> |
@@ -27,6 +28,7 @@ | |||
27 | 28 | ||
28 | static bool terminate_request = false; | 29 | static bool terminate_request = false; |
29 | static int exit_value = 0; | 30 | static int exit_value = 0; |
31 | static struct rlimit original_nofile_rlimit = {0}; | ||
30 | struct sway_server server = {0}; | 32 | struct sway_server server = {0}; |
31 | struct sway_debug debug = {0}; | 33 | struct sway_debug debug = {0}; |
32 | 34 | ||
@@ -169,6 +171,33 @@ static bool drop_permissions(void) { | |||
169 | return true; | 171 | return true; |
170 | } | 172 | } |
171 | 173 | ||
174 | static void increase_nofile_limit(void) { | ||
175 | if (getrlimit(RLIMIT_NOFILE, &original_nofile_rlimit) != 0) { | ||
176 | sway_log_errno(SWAY_ERROR, "Failed to bump max open files limit: " | ||
177 | "getrlimit(NOFILE) failed"); | ||
178 | return; | ||
179 | } | ||
180 | |||
181 | struct rlimit new_rlimit = original_nofile_rlimit; | ||
182 | new_rlimit.rlim_cur = new_rlimit.rlim_max; | ||
183 | if (setrlimit(RLIMIT_NOFILE, &new_rlimit) != 0) { | ||
184 | sway_log_errno(SWAY_ERROR, "Failed to bump max open files limit: " | ||
185 | "setrlimit(NOFILE) failed"); | ||
186 | sway_log(SWAY_INFO, "Running with %d max open files", | ||
187 | (int)original_nofile_rlimit.rlim_cur); | ||
188 | } | ||
189 | } | ||
190 | |||
191 | void restore_nofile_limit(void) { | ||
192 | if (original_nofile_rlimit.rlim_cur == 0) { | ||
193 | return; | ||
194 | } | ||
195 | if (setrlimit(RLIMIT_NOFILE, &original_nofile_rlimit) != 0) { | ||
196 | sway_log_errno(SWAY_ERROR, "Failed to restore max open files limit: " | ||
197 | "setrlimit(NOFILE) failed"); | ||
198 | } | ||
199 | } | ||
200 | |||
172 | void enable_debug_flag(const char *flag) { | 201 | void enable_debug_flag(const char *flag) { |
173 | if (strcmp(flag, "damage=highlight") == 0) { | 202 | if (strcmp(flag, "damage=highlight") == 0) { |
174 | debug.damage = DAMAGE_HIGHLIGHT; | 203 | debug.damage = DAMAGE_HIGHLIGHT; |
@@ -349,6 +378,8 @@ int main(int argc, char **argv) { | |||
349 | exit(EXIT_FAILURE); | 378 | exit(EXIT_FAILURE); |
350 | } | 379 | } |
351 | 380 | ||
381 | increase_nofile_limit(); | ||
382 | |||
352 | // handle SIGTERM signals | 383 | // handle SIGTERM signals |
353 | signal(SIGTERM, sig_handler); | 384 | signal(SIGTERM, sig_handler); |
354 | signal(SIGINT, sig_handler); | 385 | signal(SIGINT, sig_handler); |