Use CLOEXEC for ConnectionNumber(dpy) as well

This commit is contained in:
Ashish Kumar Yadav 2021-08-03 19:38:37 +05:30
parent 56b636492a
commit be75f21fd2

View file

@ -51,7 +51,6 @@ buttonhandler(int sig, siginfo_t *info, void *ucontext)
char button[] = { '0' + (info->si_value.sival_int & 0xff), '\0' }; char button[] = { '0' + (info->si_value.sival_int & 0xff), '\0' };
char *arg[] = { block->pathc, button, NULL }; char *arg[] = { block->pathc, button, NULL };
close(ConnectionNumber(dpy));
setsid(); setsid();
execv(arg[0], arg); execv(arg[0], arg);
perror("buttonhandler - child - execv"); perror("buttonhandler - child - execv");
@ -182,7 +181,6 @@ updateblock(Block *block, int sigval)
cleanup(); cleanup();
exit(1); exit(1);
case 0: case 0:
close(ConnectionNumber(dpy));
close(fd[0]); close(fd[0]);
if (fd[1] != STDOUT_FILENO) { if (fd[1] != STDOUT_FILENO) {
if (dup2(fd[1], STDOUT_FILENO) != STDOUT_FILENO) { if (dup2(fd[1], STDOUT_FILENO) != STDOUT_FILENO) {
@ -298,12 +296,16 @@ writepid()
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int xfd;
writepid(); writepid();
if (!(dpy = XOpenDisplay(NULL))) { if (!(dpy = XOpenDisplay(NULL))) {
fputs("Error: could not open display.\n", stderr); fputs("Error: could not open display.\n", stderr);
unlink(LOCKFILE); unlink(LOCKFILE);
return 1; return 1;
} }
xfd = ConnectionNumber(dpy);
fcntl(xfd, F_SETFD, fcntl(xfd, F_GETFD) | FD_CLOEXEC);
setupsignals(); setupsignals();
statusloop(); statusloop();
cleanup(); cleanup();