]> git.webhop.me Git - lcd4linux.git/commitdiff
initialize fifo on first use
authormichael <michael@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Tue, 6 Jan 2009 06:42:05 +0000 (06:42 +0000)
committermichael <michael@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Tue, 6 Jan 2009 06:42:05 +0000 (06:42 +0000)
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@942 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

plugin_fifo.c

index f8be4c84cfca6a96b8d9848b66de2b7b549a5fa0..3a41e04b049ffd51fff81b0be523f3274378df94 100644 (file)
@@ -149,11 +149,37 @@ static int openFifo()
 }
 
 
+static void startFifo(void)
+{
+    static int started = 0;
+
+    if (started)
+       return;
+    
+    started = 1;
+    
+    configure_fifo();
+    fd.path = fifopath;
+    fd.input = -1;
+    fd.created = 0;
+    openFifo();
+
+    /* ignore broken pipe */
+    signal(SIGPIPE, SIG_IGN);
+
+    memset(msg, 0, FIFO_BUFFER_SIZE);
+
+}
+
+
 static void fiforead(RESULT * result)
 {
     char buf[FIFO_BUFFER_SIZE];
     unsigned int i;
     int bytes = 1;
+
+    startFifo();
+
     memset(buf, 0, FIFO_BUFFER_SIZE);
     strcat(buf, "ERROR");
 
@@ -184,18 +210,6 @@ static void fiforead(RESULT * result)
 /* plugin initialization */
 int plugin_init_fifo(void)
 {
-    configure_fifo();
-    fd.path = fifopath;
-    fd.input = -1;
-    fd.created = 0;
-    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;
 }
@@ -203,7 +217,6 @@ int plugin_init_fifo(void)
 
 void plugin_exit_fifo(void)
 {
-
     /* close filedescriptors */
     closeFifo();
 }