First use of string-queue utility.
[egate.git] / kernel / main.c
index fd6ef7e..e6d0081 100644 (file)
@@ -2,7 +2,10 @@
  * Europagate, 1995
  *
  * $Log: main.c,v $
- * Revision 1.13  1995/03/28 08:01:25  adam
+ * Revision 1.14  1995/03/28 11:42:34  adam
+ * First use of string-queue utility.
+ *
+ * Revision 1.13  1995/03/28  08:01:25  adam
  * FIFO existence is used to test for a running kernel.
  *
  * Revision 1.12  1995/03/27  12:51:05  adam
 #include <fcntl.h>
 
 #include <gip.h>
+#include <strqueue.h>
 #include "kernel.h"
 
 FILE *reply_fd = stdout;
 
 struct gw_kernel_info info;
 
-static void kernel_events (int userid)
+static void kernel_events (struct str_queue *queue, int userid)
 {
     char fifo_client_name[1024];
     char fifo_server_name[1024];
+    char line_buf[1024];
     GIP gip;
     fd_set set_r;
     int r, gip_fd;
@@ -118,7 +123,11 @@ static void kernel_events (int userid)
             if (!strcmp (command, "mail"))
            {
                gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Incoming mail...\n");
-                urp (gip_fd);
+                while (lgets (line_buf, sizeof(line_buf)-1, gip_fd))
+                    str_queue_enq (queue, line_buf);
+                urp (queue);
+                while (str_queue_deq (queue, 0, 0))
+                    ;
            }
            else if (!strcmp (command, "stop"))
            {
@@ -140,6 +149,7 @@ static void kernel_events (int userid)
 int main (int argc, char **argv)
 {
     int userid = -1;
+    struct str_queue *queue;
 
     info.kernel_res = NULL;
     info.default_res = "default.res";
@@ -289,10 +299,20 @@ int main (int argc, char **argv)
             info.default_res = *argv;
     }
     read_kernel_res ();
+    if (!(queue = str_queue_mk ()))
+    {
+        gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, KERNEL_LOG, "str_queue_mk");
+        exit (1);
+    }
     if (userid != -1)
-        kernel_events (userid);
+        kernel_events (queue, userid);
     else
-        urp (0);
+    {
+        char line_buf[512];
+        while (lgets (line_buf, sizeof(line_buf)-1, 0))
+            str_queue_enq (queue, line_buf);
+        urp (queue);
+    }
     return 0;
 }