From 365a047960e85337a4829cfd8f39a2d7345830c5 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Yadav Date: Sat, 3 Oct 2020 16:02:07 +0530 Subject: [PATCH] Improved buttonhandler --- dwmblocks.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/dwmblocks.c b/dwmblocks.c index bc65b2c..5f042bd 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -44,25 +44,24 @@ void buttonhandler(int signal, siginfo_t *si, void *ucontext) { signal = si->si_value.sival_int >> 8; - switch (fork()) { - case -1: - perror("buttonhandler - fork"); - exit(1); - case 0: - close(ConnectionNumber(dpy)); - for (Block *current = blocks; current->pathu; current++) { - if (current->signal == signal) { + for (Block *current = blocks; current->pathu; current++) + if (current->signal == signal) + switch (fork()) { + case -1: + perror("buttonhandler - fork"); + break; + case 0: + { char button[] = { '0' + (si->si_value.sival_int & 0xff), '\0' }; char *arg[] = { current->pathc, button, NULL }; + close(ConnectionNumber(dpy)); setsid(); execv(arg[0], arg); perror("buttonhandler - child - execv"); _exit(127); } } - exit(0); - } } void