From d69593f1cd0bdcde074ed68161854f841d19747c Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Sat, 25 Apr 2020 21:19:54 +0200 Subject: [PATCH] implemented pull request from original project to handle all otherwise unhandled signals, prevents crash --- Makefile | 2 +- config.h | 10 ++-------- dwmblocks.c | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index c45a563..c408cfe 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/config.h b/config.h index ee1d86d..9a0116a 100644 --- a/config.h +++ b/config.h @@ -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}, }; diff --git a/dwmblocks.c b/dwmblocks.c index 6a62dc5..8de5120 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -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) {