From be75f21fd2c04fc0484be92896422c78ce056943 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Yadav Date: Tue, 3 Aug 2021 19:38:37 +0530 Subject: [PATCH] Use CLOEXEC for ConnectionNumber(dpy) as well --- dwmblocks.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dwmblocks.c b/dwmblocks.c index 4ba6401..d58450b 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -51,7 +51,6 @@ buttonhandler(int sig, siginfo_t *info, void *ucontext) char button[] = { '0' + (info->si_value.sival_int & 0xff), '\0' }; char *arg[] = { block->pathc, button, NULL }; - close(ConnectionNumber(dpy)); setsid(); execv(arg[0], arg); perror("buttonhandler - child - execv"); @@ -182,7 +181,6 @@ updateblock(Block *block, int sigval) cleanup(); exit(1); case 0: - close(ConnectionNumber(dpy)); close(fd[0]); if (fd[1] != STDOUT_FILENO) { if (dup2(fd[1], STDOUT_FILENO) != STDOUT_FILENO) { @@ -298,12 +296,16 @@ writepid() int main(int argc, char *argv[]) { + int xfd; + writepid(); if (!(dpy = XOpenDisplay(NULL))) { fputs("Error: could not open display.\n", stderr); unlink(LOCKFILE); return 1; } + xfd = ConnectionNumber(dpy); + fcntl(xfd, F_SETFD, fcntl(xfd, F_GETFD) | FD_CLOEXEC); setupsignals(); statusloop(); cleanup();