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/i3.c b/modules/i3.c index a7f3cc0..22b6d4b 100644 --- a/modules/i3.c +++ b/modules/i3.c @@ -621,7 +621,7 @@ run(struct module *mod) if (!i3_get_socket_address(&addr)) return 1; - int sock = socket(AF_UNIX, SOCK_STREAM, 0); + int sock = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); if (sock == -1) { LOG_ERRNO("failed to create UNIX socket"); return 1; diff --git a/modules/mpd.c b/modules/mpd.c index b2e9e6e..27992d3 100644 --- a/modules/mpd.c +++ b/modules/mpd.c @@ -223,7 +223,7 @@ wait_for_socket_create(const struct module *mod) struct stat st; if (stat(m->host, &st) == 0 && S_ISSOCK(st.st_mode)) { - int s = socket(AF_UNIX, SOCK_STREAM, 0); + int s = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); struct sockaddr_un addr = {.sun_family = AF_UNIX}; strncpy(addr.sun_path, m->host, sizeof(addr.sun_path) - 1); diff --git a/modules/network.c b/modules/network.c index 3bff716..34980fa 100644 --- a/modules/network.c +++ b/modules/network.c @@ -167,7 +167,7 @@ nl_pid_value(void) static int netlink_connect_rt(void) { - int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); + int sock = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE); if (sock == -1) { LOG_ERRNO("failed to create netlink socket"); return -1; @@ -191,7 +191,7 @@ netlink_connect_rt(void) static int netlink_connect_genl(void) { - int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); + int sock = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_GENERIC); if (sock == -1) { LOG_ERRNO("failed to create netlink socket"); return -1; diff --git a/modules/removables.c b/modules/removables.c index 6727afa..d8fe7c9 100644 --- a/modules/removables.c +++ b/modules/removables.c @@ -164,11 +164,17 @@ content(struct module *mod) static void find_mount_points(const char *dev_path, mount_point_list_t *mount_points) { - FILE *f = fopen("/proc/self/mountinfo", "r"); - assert(f != NULL); + int fd = open("/proc/self/mountinfo", O_RDONLY | O_CLOEXEC); + FILE *f = fd >= 0 ? fdopen(fd, "r") : NULL; + + if (fd < 0 || f == NULL) { + LOG_ERRNO("failed to open /proc/self/mountinfo"); + if (fd >= 0) + close(fd); + return; + } char line[4096]; - while (fgets(line, sizeof(line), f) != NULL) { char *dev = NULL, *path = NULL; @@ -641,7 +647,7 @@ run(struct module *mod) /* To be able to poll() mountinfo for changes, to detect * mount/unmount operations */ - int mount_info_fd = open("/proc/self/mountinfo", O_RDONLY); + int mount_info_fd = open("/proc/self/mountinfo", O_RDONLY | O_CLOEXEC); int ret = 1; diff --git a/modules/script.c b/modules/script.c index 254aac4..f701e99 100644 --- a/modules/script.c +++ b/modules/script.c @@ -396,7 +396,7 @@ execute_script(struct module *mod) /* Stdout redirection pipe */ int comm_pipe[2]; - if (pipe(comm_pipe) < 0) { + if (pipe2(comm_pipe, O_CLOEXEC) < 0) { LOG_ERRNO("failed to create stdin/stdout redirection pipe"); close(exec_pipe[0]); close(exec_pipe[1]); @@ -444,7 +444,7 @@ execute_script(struct module *mod) close(comm_pipe[0]); /* Re-direct stdin/stdout */ - int dev_null = open("/dev/null", O_RDONLY); + int dev_null = open("/dev/null", O_RDONLY | O_CLOEXEC); if (dev_null < 0) goto fail; @@ -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/modules/sway-xkb.c b/modules/sway-xkb.c index 9841feb..6632ab7 100644 --- a/modules/sway-xkb.c +++ b/modules/sway-xkb.c @@ -267,7 +267,7 @@ run(struct module *mod) if (!i3_get_socket_address(&addr)) return 1; - int sock = socket(AF_UNIX, SOCK_STREAM, 0); + int sock = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); if (sock == -1) { LOG_ERRNO("failed to create UNIX socket"); return 1; 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: