]> git.lizzy.rs Git - bspwm.git/commitdiff
Set CLOEXEC on the sockets except when restarting
authorBastien Dejean <nihilhill@gmail.com>
Fri, 28 May 2021 09:33:07 +0000 (11:33 +0200)
committerBastien Dejean <nihilhill@gmail.com>
Fri, 28 May 2021 09:33:07 +0000 (11:33 +0200)
Fixes #1292.

src/bspwm.c
src/subscribe.c

index dca03fdea238a2975da5239830882564eec0a69c..9c6be76c82972e5e5656a736b70003f6d85b679b 100644 (file)
@@ -30,6 +30,7 @@
 #include <sys/wait.h>
 #include <sys/socket.h>
 #include <sys/un.h>
+#include <fcntl.h>
 #include <signal.h>
 #include <unistd.h>
 #include <stdbool.h>
@@ -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])) {
index 328ca128e4153691a3c12d55a39b418d7b27d949..494c466e3a520b490daadb617003fe731bf6d2fd 100644 (file)
@@ -27,6 +27,7 @@
 #include <unistd.h>
 #include <ctype.h>
 #include <stdarg.h>
+#include <fcntl.h>
 #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) {