diff options
author | michux <michux@3ae390bd-cb1e-0410-b409-cd5a39f66f1f> | 2008-04-15 09:50:27 +0000 |
---|---|---|
committer | michux <michux@3ae390bd-cb1e-0410-b409-cd5a39f66f1f> | 2008-04-15 09:50:27 +0000 |
commit | c34fa6efea48c1db2b44e37607e0991b54c0879b (patch) | |
tree | 5c410f287db14bb7ad12090f31fcdfbc07a96e7f | |
parent | 8c9892fea89f800089d450b719147fb70ed52c58 (diff) | |
download | lcd4linux-c34fa6efea48c1db2b44e37607e0991b54c0879b.tar.gz |
add signal handler, improve error check
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@876 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
Diffstat (limited to '')
-rw-r--r-- | plugin_fifo.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/plugin_fifo.c b/plugin_fifo.c index 59422e5..fda6f0b 100644 --- a/plugin_fifo.c +++ b/plugin_fifo.c @@ -151,16 +151,19 @@ static int openFifo() static void fiforead(RESULT * result) { char buf[FIFO_BUFFER_SIZE]; - int i, bytes = 1; + unsigned int i; + int bytes = 1; memset(buf, 0, FIFO_BUFFER_SIZE); strcat(buf, "ERROR"); + if (checkFifo() == 0) { memset(buf, 0, FIFO_BUFFER_SIZE); - while (bytes > 0 && errno != EINTR) { + + while (bytes > 0 && errno != EINTR) { bytes = read(fd.input, buf, FIFO_BUFFER_SIZE); } - if (bytes < 0) { + if (bytes < 0 || errno > 0) { error("[FIFO] Error %i: %s", errno, strerror(errno)); } else { if (strlen(buf) > 0) { @@ -172,7 +175,6 @@ static void fiforead(RESULT * result) } } } - /* store result */ SetResult(&result, R_STRING, msg); } @@ -188,6 +190,10 @@ int plugin_init_fifo(void) if (openFifo() < 0) { return -1; } + + /* ignore broken pipe */ + signal(SIGPIPE, SIG_IGN); + memset(msg, 0, FIFO_BUFFER_SIZE); AddFunction("fifo::read", 0, fiforead); return 0; |