X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=dwmblocks.c;h=8668f042d77bea8510570564fe82f78de5bc5463;hb=8893f2d08aed826532fbb7a7b63e20c5bd938563;hp=ad8e91cb0f26d865cf87b1c5fd4ccfb22443635b;hpb=377f9903318d89934593348cda91c3c8fef4158c;p=dwmblocks.git diff --git a/dwmblocks.c b/dwmblocks.c index ad8e91c..8668f04 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -13,15 +13,17 @@ 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); void setupsignals(); +void sighandler(int signum); +#endif int getstatus(char *str, char *last); void setroot(); void statusloop(); -void sighandler(int signum); void termhandler(int signum); @@ -35,14 +37,6 @@ 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) { @@ -65,13 +59,14 @@ void getcmds(int time) { const Block* current; for(int i = 0; i < LENGTH(blocks); i++) - { + { current = blocks + i; if ((current->interval != 0 && time % current->interval == 0) || time == -1) getcmd(current,statusbar[i]); } } +#ifndef __OpenBSD__ void getsigcmds(int signal) { const Block *current; @@ -85,13 +80,18 @@ 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) signal(SIGRTMIN+blocks[i].signal, sighandler); } } +#endif int getstatus(char *str, char *last) { @@ -128,7 +128,9 @@ void pstdout() void statusloop() { +#ifndef __OpenBSD__ setupsignals(); +#endif int i = 0; getcmds(-1); while(statusContinue) @@ -140,12 +142,21 @@ void statusloop() } } +#ifndef __OpenBSD__ +/* this signal handler should do nothing */ +void dummysighandler(int signum) +{ + return; +} +#endif +#ifndef __OpenBSD__ void sighandler(int signum) { getsigcmds(signum-SIGRTMIN); writestatus(); } +#endif void termhandler(int signum) { @@ -156,7 +167,7 @@ void termhandler(int signum) int main(int argc, char** argv) { for(int i = 0; i < argc; i++) - { + { if (!strcmp("-d",argv[i])) delim = argv[++i][0]; else if(!strcmp("-p",argv[i]))