diff options
author | Jon Gjengset <jon@thesquareplanet.com> | 2013-09-05 20:39:53 +0100 |
---|---|---|
committer | Jon Gjengset <jon@thesquareplanet.com> | 2013-09-05 20:39:53 +0100 |
commit | 0c0a5897e1ae5bd4670d2aeb83d26ec61d666851 (patch) | |
tree | 03a01cb11050832ced327a2f04f6301eb2ec0fca /mktrayicon.c | |
parent | Make 'none' default icon (diff) | |
download | mktrayicon-0c0a5897e1ae5bd4670d2aeb83d26ec61d666851.tar.gz mktrayicon-0c0a5897e1ae5bd4670d2aeb83d26ec61d666851.tar.bz2 mktrayicon-0c0a5897e1ae5bd4670d2aeb83d26ec61d666851.zip |
Read all messages from fifo, not just first of each write
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; } |