From b4f093c9cb5e26277c79e24550294e6bd9fc8db7 Mon Sep 17 00:00:00 2001 From: sewn Date: Sun, 19 May 2024 20:07:11 +0300 Subject: [PATCH] add rlimit_max --- patches/rlimit_max/README.md | 12 ++++ patches/rlimit_max/rlimit_max.patch | 91 +++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 patches/rlimit_max/README.md create mode 100644 patches/rlimit_max/rlimit_max.patch diff --git a/patches/rlimit_max/README.md b/patches/rlimit_max/README.md new file mode 100644 index 0000000..255d2c7 --- /dev/null +++ b/patches/rlimit_max/README.md @@ -0,0 +1,12 @@ +### Description +Sets the current maximum open file descriptors to the maximum available limit. + +This patch is useful - and solves issue [#628](https://codeberg.org/dwl/dwl/issues/628) for running heavy Xwayland applications on systems that do not provide limits out of the box. + +### Download +- [git branch](https://codeberg.org/sewn/dwl/src/branch/rlimit_max) +- [2024-05-19](https://codeberg.org/dwl/dwl-patches/raw/branch/main/patches/rlimit_max/rlimit_max.patch) + +### Authors +- [sewn](https://codeberg.org/sewn) + diff --git a/patches/rlimit_max/rlimit_max.patch b/patches/rlimit_max/rlimit_max.patch new file mode 100644 index 0000000..f8ea51f --- /dev/null +++ b/patches/rlimit_max/rlimit_max.patch @@ -0,0 +1,91 @@ +From 1a3a3290f1ecc3afe7d455c05b2742060406dae0 Mon Sep 17 00:00:00 2001 +From: sewn +Date: Sun, 19 May 2024 20:06:32 +0300 +Subject: [PATCH] set max open file descriptors to available max + +--- + dwl.c | 23 +++++++++++++++++++++++ + 1 file changed, 23 insertions(+) + +diff --git a/dwl.c b/dwl.c +index bf763df..eabea11 100644 +--- a/dwl.c ++++ b/dwl.c +@@ -7,6 +7,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -308,6 +309,7 @@ static void pointerfocus(Client *c, struct wlr_surface *surface, + double sx, double sy, uint32_t time); + static void printstatus(void); + static void quit(const Arg *arg); ++static void restorerlimit(void); + static void rendermon(struct wl_listener *listener, void *data); + static void requestdecorationmode(struct wl_listener *listener, void *data); + static void requeststartdrag(struct wl_listener *listener, void *data); +@@ -350,6 +352,7 @@ static void zoom(const Arg *arg); + + /* variables */ + static const char broken[] = "broken"; ++static struct rlimit og_rlimit; + static pid_t child_pid = -1; + static int locked; + static void *exclusive_focus; +@@ -1951,6 +1954,15 @@ quit(const Arg *arg) + wl_display_terminate(dpy); + } + ++void ++restorerlimit(void) ++{ ++ if (og_rlimit.rlim_cur == 0) ++ return; ++ if (setrlimit(RLIMIT_NOFILE, &og_rlimit) < 0) ++ die("setrlimit:"); ++} ++ + void + rendermon(struct wl_listener *listener, void *data) + { +@@ -2080,6 +2092,7 @@ run(char *startup_cmd) + if ((child_pid = fork()) < 0) + die("startup: fork:"); + if (child_pid == 0) { ++ restorerlimit(); + dup2(piperw[0], STDIN_FILENO); + close(piperw[0]); + close(piperw[1]); +@@ -2271,9 +2284,18 @@ setup(void) + { + struct xkb_context *context; + struct xkb_keymap *keymap; ++ struct rlimit new_rlimit; + + int i, sig[] = {SIGCHLD, SIGINT, SIGTERM, SIGPIPE}; + struct sigaction sa = {.sa_flags = SA_RESTART, .sa_handler = handlesig}; ++ ++ if (getrlimit(RLIMIT_NOFILE, &og_rlimit) < 0) ++ die("getrlimit:"); ++ new_rlimit = og_rlimit; ++ new_rlimit.rlim_cur = new_rlimit.rlim_max; ++ if (setrlimit(RLIMIT_NOFILE, &new_rlimit) < 0) ++ die("setrlimit:"); ++ + sigemptyset(&sa.sa_mask); + + for (i = 0; i < (int)LENGTH(sig); i++) +@@ -2530,6 +2552,7 @@ void + spawn(const Arg *arg) + { + if (fork() == 0) { ++ restorerlimit(); + dup2(STDERR_FILENO, STDOUT_FILENO); + setsid(); + execvp(((char **)arg->v)[0], (char **)arg->v); +-- +2.45.0 +