From: Bastien Dejean Date: Fri, 28 May 2021 09:33:07 +0000 (+0200) Subject: Set CLOEXEC on the sockets except when restarting X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=0d2aa1ce7cfe2f1d3d5894bc28bf13f5fdc0c671;p=bspwm.git Set CLOEXEC on the sockets except when restarting Fixes #1292. --- diff --git a/src/bspwm.c b/src/bspwm.c index dca03fd..9c6be76 100644 --- a/src/bspwm.c +++ b/src/bspwm.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -190,6 +191,8 @@ int main(int argc, char *argv[]) } } + fcntl(sock_fd, F_SETFD, FD_CLOEXEC | fcntl(sock_fd, F_GETFD)); + signal(SIGINT, sig_handler); signal(SIGHUP, sig_handler); signal(SIGTERM, sig_handler); @@ -282,6 +285,8 @@ int main(int argc, char *argv[]) xcb_disconnect(dpy); if (restart) { + fcntl(sock_fd, F_SETFD, ~FD_CLOEXEC & fcntl(sock_fd, F_GETFD)); + int rargc; for (rargc = 0; rargc < argc; rargc++) { if (streq("-s", argv[rargc])) { diff --git a/src/subscribe.c b/src/subscribe.c index 328ca12..494c466 100644 --- a/src/subscribe.c +++ b/src/subscribe.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "bspwm.h" #include "desktop.h" #include "settings.h" @@ -63,7 +64,10 @@ void remove_subscriber(subscriber_list_t *sb) if (sb == subscribe_tail) { subscribe_tail = a; } - if (!restart) { + if (restart) { + int cli_fd = fileno(sb->stream); + fcntl(cli_fd, F_SETFD, ~FD_CLOEXEC & fcntl(cli_fd, F_GETFD)); + } else { fclose(sb->stream); unlink(sb->fifo_path); } @@ -80,6 +84,8 @@ void add_subscriber(subscriber_list_t *sb) sb->prev = subscribe_tail; subscribe_tail = sb; } + int cli_fd = fileno(sb->stream); + fcntl(cli_fd, F_SETFD, FD_CLOEXEC | fcntl(cli_fd, F_GETFD)); if (sb->field & SBSC_MASK_REPORT) { print_report(sb->stream); if (sb->count-- == 1) {