Replaced signal masking with signal blocking

This commit is contained in:
Ashish Kumar Yadav 2020-07-26 02:02:38 +05:30
parent 1e83bd57c9
commit e47d1d0b50

View file

@ -29,6 +29,7 @@ typedef struct {
static void buttonhandler(int signal, siginfo_t *si, void *ucontext); static void buttonhandler(int signal, siginfo_t *si, void *ucontext);
static void getcmd(Block *block, int sigval); static void getcmd(Block *block, int sigval);
static void setroot();
static void setupsignals(); static void setupsignals();
static void sighandler(int signal, siginfo_t *si, void *ucontext); static void sighandler(int signal, siginfo_t *si, void *ucontext);
static void statusloop(); static void statusloop();
@ -111,6 +112,17 @@ getcmd(Block *block, int sigval)
} }
} }
void
setroot()
{
if (updatestatus()) {
sigprocmask(SIG_BLOCK, &blocksigmask, NULL);
XStoreName(dpy, DefaultRootWindow(dpy), statusstr);
XSync(dpy, False);
sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL);
}
}
void void
setupsignals() setupsignals()
{ {
@ -145,7 +157,7 @@ setupsignals()
/* to handle update signals for individual blocks */ /* to handle update signals for individual blocks */
sa.sa_flags |= SA_NODEFER; sa.sa_flags |= SA_NODEFER;
sa.sa_mask = blocksigmask; // sigemptyset(&sa.sa_mask);
sa.sa_sigaction = sighandler; sa.sa_sigaction = sighandler;
for (Block *current = blocks; current->pathu; current++) for (Block *current = blocks; current->pathu; current++)
if (current->signal > 0) if (current->signal > 0)
@ -157,18 +169,18 @@ sighandler(int signal, siginfo_t *si, void *ucontext)
{ {
signal -= SIGRTMIN; signal -= SIGRTMIN;
for (Block *current = blocks; current->pathu; current++) for (Block *current = blocks; current->pathu; current++)
if (current->signal == signal) if (current->signal == signal) {
sigprocmask(SIG_BLOCK, &blocksigmask, NULL);
getcmd(current, si->si_value.sival_int); getcmd(current, si->si_value.sival_int);
if (updatestatus()) { sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL);
XStoreName(dpy, DefaultRootWindow(dpy), statusstr);
XSync(dpy, False);
} }
setroot();
} }
void void
statusloop() statusloop()
{ {
int i = 0; int i;
/* first run */ /* first run */
for (Block *current = blocks; current->pathu; current++) for (Block *current = blocks; current->pathu; current++)
@ -177,7 +189,9 @@ statusloop()
getcmd(current, NILL); getcmd(current, NILL);
sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL); sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL);
} }
goto enterloop; setroot();
sleep(SLEEPINTERVAL);
i = SLEEPINTERVAL;
/* main loop */ /* main loop */
while (statuscontinue) { while (statuscontinue) {
for (Block *current = blocks; current->pathu; current++) for (Block *current = blocks; current->pathu; current++)
@ -186,13 +200,7 @@ statusloop()
getcmd(current, NILL); getcmd(current, NILL);
sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL); sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL);
} }
enterloop: setroot();
if (updatestatus()) {
sigprocmask(SIG_BLOCK, &blocksigmask, NULL);
XStoreName(dpy, DefaultRootWindow(dpy), statusstr);
XSync(dpy, False);
sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL);
}
sleep(SLEEPINTERVAL); sleep(SLEEPINTERVAL);
i += SLEEPINTERVAL; i += SLEEPINTERVAL;
} }