From fd014dc33ba9285db30a5609352bc768978c9d03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 29 Mar 2022 18:23:55 +0200 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20loop=2065536=20FDs,=20trying=20?= =?UTF-8?q?to=20close=20them,=20when=20fork+exec:ing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All FDs should now have the CLOEXEC flag set, and thus there’s no longer needed to manually loop “all” possible FDs and (trying to) close them. Note: the alsa module (alsalib, actually) is “racy” - while booting up, it temporarily opens the asoundrc file without CLOEXEC. If e.g. the script module starts its script inside this window, it’ll have a leaked FD. Not much we can do about it though :/ Closes #169 --- CHANGELOG.md | 3 +++ modules/script.c | 10 ---------- particle.c | 5 ----- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01d9ab8..d6e8b90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,9 @@ * i3: fixed “missing workspace indicator” (_err: modules/i3.c:94: workspace reply/event without 'name' and/or 'output', and/or 'focus' properties_). +* Slow/laggy behavior when quickly spawning many `on-click` handlers, + e.g. when handling mouse wheel events + (https://codeberg.org/dnkl/yambar/issues/169). ### Security diff --git a/modules/script.c b/modules/script.c index 5b3b51a..f701e99 100644 --- a/modules/script.c +++ b/modules/script.c @@ -458,16 +458,6 @@ execute_script(struct module *mod) close(comm_pipe[1]); comm_pipe[1] = -1; - /* Close *all* other FDs */ - for (int i = STDERR_FILENO + 1; i < 65536; i++) { - if (i == exec_pipe[1]) { - /* Needed for error reporting. Automatically closed - * when execvp() succeeds */ - continue; - } - close(i); - } - execvp(m->path, argv); fail: diff --git a/particle.c b/particle.c index 7fd747c..5f6b04d 100644 --- a/particle.c +++ b/particle.c @@ -277,11 +277,6 @@ exposable_default_on_mouse(struct exposable *exposable, struct bar *bar, goto fail; } - /* Close *all* other FDs (e.g. script modules' FDs) */ - for (int i = STDERR_FILENO + 1; i < 65536; i++) - if (i != pipe_fds[1]) - close(i); - execvp(argv[0], argv); fail: