Minor changes.
[egate.git] / kernel / main.c
index 374ca49..8a5971c 100644 (file)
@@ -2,7 +2,17 @@
  * Europagate, 1995
  *
  * $Log: main.c,v $
- * Revision 1.19  1995/04/19 16:01:58  adam
+ * Revision 1.22  1995/05/03 07:37:39  adam
+ * CCL commands stop/continue implemented. New functions gw_res_{int,bool}
+ * are used when possible.
+ *
+ * Revision 1.21  1995/05/01  16:26:56  adam
+ * More work on resource monitor.
+ *
+ * Revision 1.20  1995/05/01  12:43:32  adam
+ * First work on resource monitor program.
+ *
+ * Revision 1.19  1995/04/19  16:01:58  adam
  * Some hacks to get the FIFO communication work!! Isn't reliable.
  * Resource gw.account added - default account info.
  *
@@ -97,9 +107,12 @@ static void kernel_events (struct str_queue *queue, int userid)
     struct timeval tv;
     int timeout;
     int continuation = 0;
+    int extra_fd;
+    int persist_flag;
 
-    timeout = atoi(gw_res_get (info.kernel_res, "gw.timeout", "600"));
-    gw_log (GW_LOG_DEBUG, KERNEL_LOG, "kernel event loop");
+    persist_flag = gw_res_bool (info.kernel_res, "gw.persist", 0);
+    timeout = gw_res_int (info.kernel_res, "gw.timeout", 600);
+    gw_log (GW_LOG_DEBUG, KERNEL_LOG, "event loop");
 
     sprintf (fifo_client_name, "fifo.c.%d", userid);
     sprintf (fifo_server_name, "fifo.s.%d", userid);
@@ -107,7 +120,7 @@ static void kernel_events (struct str_queue *queue, int userid)
     gip = gips_initialize (fifo_server_name);
     gips_open (gip, fifo_client_name);
     gip_fd = gip_infileno (gip);
-    open (fifo_server_name, O_WRONLY);
+    extra_fd = open (fifo_server_name, O_WRONLY);
 
     while (1)
     {
@@ -127,7 +140,7 @@ static void kernel_events (struct str_queue *queue, int userid)
        {
            gw_log (GW_LOG_STAT, KERNEL_LOG, "Timeout after %d seconds", 
                    timeout);
-           if (info.zass)
+           if (info.zass && persist_flag)
                save_p_state (userid);
            break;
        }
@@ -145,13 +158,15 @@ static void kernel_events (struct str_queue *queue, int userid)
            gw_log (GW_LOG_STAT, KERNEL_LOG, "IPC: %s", command);
             if (!strcmp (command, "mail"))
            {
-               gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Incoming mail...\n");
+               gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Incoming mail");
                 while (lgets (line_buf, sizeof(line_buf)-1, gip_fd))
                     str_queue_enq (queue, line_buf);
                urp_start (continuation, queue);
-                if (!continuation)
+                if (persist_flag && !continuation)
                    load_p_state (userid);      
-               urp_command (queue);
+               r = urp_command (queue);
+               if (persist_flag && r == 1)
+                   del_p_state (userid);
                urp_end ();
                 while (str_queue_deq (queue, 0, 0))
                     ;
@@ -168,6 +183,7 @@ static void kernel_events (struct str_queue *queue, int userid)
            continuation = 1;
        }
     }
+    close (extra_fd);
     gips_close (gip);
     gips_destroy (gip);
     unlink (fifo_client_name);
@@ -507,8 +523,7 @@ void read_kernel_res (void)
         else
         {
             strcpy (info.hostname, info.target);
-            info.port = atoi (gw_res_get
-                              (info.kernel_res, "gw.portno", "210"));
+            info.port = gw_res_int (info.kernel_res, "gw.portno", 210);
         }
     }
     else
@@ -516,8 +531,7 @@ void read_kernel_res (void)
         strncpy (info.hostname, gw_res_get (info.kernel_res,
                                             "gw.hostname", "localhost"),
                  sizeof(info.hostname)-1);
-        info.port = atoi (gw_res_get (info.kernel_res,
-                                      "gw.portno", "210"));
+        info.port = gw_res_int (info.kernel_res, "gw.portno", 210);
         strcpy (info.account, gw_res_get (info.kernel_res, "gw.account", ""));
     }
     if (info.databases)
@@ -551,8 +565,10 @@ void read_kernel_res (void)
     if (info.override_hostname)
         strncpy (info.hostname, info.override_hostname,
                  sizeof(info.hostname)-1);
-    v = gw_res_get (info.kernel_res, "gw.result.set", NULL);
-    info.setno = v ? -1 : 0;
+    if (gw_res_bool (info.kernel_res, "gw.result.set", 1))
+        info.setno = 0;
+    else
+        info.setno = -1;
 #if USE_FML
     if (!info.fml)
     {