diff options
Diffstat (limited to 'mktrayicon.c')
-rw-r--r-- | mktrayicon.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/mktrayicon.c b/mktrayicon.c index 4712d97..1a6328e 100644 --- a/mktrayicon.c +++ b/mktrayicon.c @@ -73,6 +73,7 @@ void *watch_fifo(void *argv) FILE *fifo; struct stat fifo_st; + /* outer is for open */ while (1) { if (stat(fifo_path, &fifo_st) != 0) { perror("FIFO does not exist, exiting\n"); @@ -88,10 +89,23 @@ void *watch_fifo(void *argv) break; } + /* inner is for read */ + while (1) { read = fgets(buf, 1024 * sizeof(char), fifo); - if (read == NULL || *buf == '\n') { - fprintf(stderr, "No data in pipe - did you send a command?\n"); + if (read == NULL) { + /* no more data in pipe, reopen and block */ + fclose(fifo); + break; + } + + /* trim string */ + while ((*read == '\n' || *read == ' ' || *read == '\t') && *read != '\0') { + read++; + } + + if (*read == '\0') { + /* empty command */ continue; } @@ -146,6 +160,7 @@ void *watch_fifo(void *argv) gdk_flush(); } + } return NULL; } |