Fixed exit bugs; check signals getting out of range
This commit is contained in:
parent
839261d66b
commit
a99b2b13e3
20
dwmblocks.c
20
dwmblocks.c
|
@ -73,14 +73,22 @@ setupsignals()
|
||||||
{
|
{
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
|
|
||||||
/* populate blocksigmask */
|
/* populate blocksigmask and check validity of signals */
|
||||||
sigemptyset(&blocksigmask);
|
sigemptyset(&blocksigmask);
|
||||||
sigaddset(&blocksigmask, SIGHUP);
|
sigaddset(&blocksigmask, SIGHUP);
|
||||||
sigaddset(&blocksigmask, SIGINT);
|
sigaddset(&blocksigmask, SIGINT);
|
||||||
sigaddset(&blocksigmask, SIGTERM);
|
sigaddset(&blocksigmask, SIGTERM);
|
||||||
for (Block *block = blocks; block->pathu; block++)
|
for (Block *block = blocks; block->pathu; block++) {
|
||||||
if (block->signal > 0)
|
if (block->signal <= 0)
|
||||||
|
continue;
|
||||||
|
if (block->signal > SIGRTMAX - SIGRTMIN) {
|
||||||
|
fprintf(stderr, "Error: SIGRTMIN + %d exceeds SIGRTMAX.\n", block->signal);
|
||||||
|
unlink(LOCKFILE);
|
||||||
|
XCloseDisplay(dpy);
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
sigaddset(&blocksigmask, SIGRTMIN + block->signal);
|
sigaddset(&blocksigmask, SIGRTMIN + block->signal);
|
||||||
|
}
|
||||||
|
|
||||||
/* setup signal handlers */
|
/* setup signal handlers */
|
||||||
/* to handle HUP, INT and TERM */
|
/* to handle HUP, INT and TERM */
|
||||||
|
@ -165,11 +173,13 @@ updateblock(Block *block, int sigval)
|
||||||
|
|
||||||
if (pipe(fd) == -1) {
|
if (pipe(fd) == -1) {
|
||||||
perror("updateblock - pipe");
|
perror("updateblock - pipe");
|
||||||
|
cleanup();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
switch (fork()) {
|
switch (fork()) {
|
||||||
case -1:
|
case -1:
|
||||||
perror("updateblock - fork");
|
perror("updateblock - fork");
|
||||||
|
cleanup();
|
||||||
exit(1);
|
exit(1);
|
||||||
case 0:
|
case 0:
|
||||||
close(ConnectionNumber(dpy));
|
close(ConnectionNumber(dpy));
|
||||||
|
@ -205,6 +215,7 @@ updateblock(Block *block, int sigval)
|
||||||
while (rd > 0 && (trd += rd) < CMDOUTLENGTH);
|
while (rd > 0 && (trd += rd) < CMDOUTLENGTH);
|
||||||
if (rd == -1) {
|
if (rd == -1) {
|
||||||
perror("updateblock - read");
|
perror("updateblock - read");
|
||||||
|
cleanup();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
close(fd[0]);
|
close(fd[0]);
|
||||||
|
@ -286,11 +297,12 @@ writepid()
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
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);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
writepid();
|
|
||||||
setupsignals();
|
setupsignals();
|
||||||
statusloop();
|
statusloop();
|
||||||
cleanup();
|
cleanup();
|
||||||
|
|
Loading…
Reference in a new issue