From 0c0a5897e1ae5bd4670d2aeb83d26ec61d666851 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Thu, 5 Sep 2013 20:39:53 +0100 Subject: Read all messages from fifo, not just first of each write --- mktrayicon.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'mktrayicon.c') 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; } -- cgit