]> git.webhop.me Git - lcd4linux.git/commitdiff
add signal handler, improve error check
authormichux <michux@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Tue, 15 Apr 2008 09:50:27 +0000 (09:50 +0000)
committermichux <michux@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Tue, 15 Apr 2008 09:50:27 +0000 (09:50 +0000)
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@876 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

plugin_fifo.c

index 59422e5fde49b23d78e73c6a61c7dc3be4be3710..fda6f0b0963c5ef586c8b928924cb777274b188d 100644 (file)
@@ -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;