implemented pull request from original project to handle all otherwise unhandled signals, prevents crash

This commit is contained in:
Alexander Bocken 2020-04-25 21:19:54 +02:00
parent 932802d52c
commit d69593f1cd
3 changed files with 25 additions and 9 deletions

View File

@ -1,6 +1,6 @@
PREFIX ?= /usr/local
output: dwmblocks.c blocks.h
output: dwmblocks.c config.h
cc `pkg-config --cflags x11` `pkg-config --libs x11` dwmblocks.c -o dwmblocks
clean:
rm -f *.o *.gch dwmblocks

View File

@ -4,19 +4,13 @@ static const Block blocks[] = {
{"", "music", 3600, 11},
{"", "getpomminutesft", 100, 3},
{"", "getpomminutes", 100, 3},
/* {"", {"weather", 3600, 5},*/
/* {"", "weather", 3600, 5},*/
{"", "cpu", 5, 0},
/* { "", "sync_status", 4, 0},*/
{"", "getmail", 20, 13},
/* {"", "btstatus", 2, 17},*/
/* {"", "memory", 5, 0},*/
{"", "news", 600, 13},
{"", "getbright", 4, 2},
{"", "volume", 1, 10},
/* { "", "amixer get Master | grep -o \"\\(\\[off\\]\\|[0-9]*%\\)\"", 0, 10}*/
/* {"", "sed \"s/$/%/\" /sys/class/power_supply/BAT?/capacity", 5, 12},*/
/* {"", "echo $( battery_dwm BAT0)", 5, 12},*/
{"", "clock", 10, 12}, //divert RTMIN update to clock since dwmblocks seems to crash if it's unhandled
{"", "clock", 10, 0},
{"", "internet", 10, 0},
};

View File

@ -13,7 +13,9 @@ typedef struct {
unsigned int interval;
unsigned int signal;
} Block;
void dummysighandler(int num);
void sighandler(int num);
void replace(char *str, char old, char new);
void getcmds(int time);
#ifndef __OpenBSD__
void getsigcmds(int signal);
@ -36,6 +38,14 @@ static char statusstr[2][256];
static int statusContinue = 1;
static void (*writestatus) () = setroot;
void replace(char *str, char old, char new)
{
int N = strlen(str);
for(int i = 0; i < N; i++)
if(str[i] == old)
str[i] = new;
}
//opens process *cmd and stores output in *output
void getcmd(const Block *block, char *output)
{
@ -79,6 +89,10 @@ void getsigcmds(int signal)
void setupsignals()
{
/* initialize all real time signals with dummy handler */
for(int i = SIGRTMIN; i <= SIGRTMAX; i++)
signal(i, dummysighandler);
for(int i = 0; i < LENGTH(blocks); i++)
{
if (blocks[i].signal > 0)
@ -137,6 +151,14 @@ void statusloop()
}
}
#ifndef __OpenBSD__
/* this signal handler should do nothing */
void dummysighandler(int signum)
{
return;
}
#endif
#ifndef __OpenBSD__
void sighandler(int signum)
{