Added a few more error checks to the show command.
[egate.git] / kernel / monitor.c
index 43249b0..e385ec2 100644 (file)
  * Europagate, 1995
  *
  * $Log: monitor.c,v $
- * Revision 1.8  1995/05/16 09:40:42  adam
+ * Revision 1.9  1995/05/17 10:51:32  adam
+ * Added a few more error checks to the show command.
+ *
+ * Revision 1.8  1995/05/16  09:40:42  adam
  * LICENSE. Setting of CCL token names (and/or/not/set) in read_kernel_res.
  *
  * Revision 1.7  1995/05/03  12:18:46  adam
@@ -189,7 +192,7 @@ static void catch_child (int num)
         for (ki = ke_info_list; ki; ki = ki->next)
            if (ki->pid == pid)
                 ki->pid = -1;
-        --no_process;
+/*        --no_process;*/
     }
     signal (SIGCHLD, catch_child);
 }
@@ -365,7 +368,7 @@ static int deliver (int argc, char **argv, int id, struct str_queue *queue,
 static void monitor_events (int argc, char **argv)
 {
     GIP gip_m;
-    int r, gip_m_fd;
+    int r, gip_m_fd, too_many;
     char line_buf[1024];
     fd_set set_r;
     char command[128], *cp;
@@ -403,6 +406,7 @@ static void monitor_events (int argc, char **argv)
                 exit (0);
             }
             /* deliver any unsent messages to Email kernels */
+            too_many = 0;
             for (ki = ke_info_list; ki; ki = ki->next)
             {
                 if (!ki->queue)
@@ -414,7 +418,35 @@ static void monitor_events (int argc, char **argv)
                     ++no_process;
                 if (r == 1 || r == 2)   /* transfer at all? */
                     str_queue_rm (&ki->queue);
+                if (r == 0)             /* too many pending? */
+                    too_many++;
+            }
+#if 0
+            if (too_many)
+            {
+                gw_log (GW_LOG_DEBUG, module, "%d too many pending",
+                        too_many);
+                for (ki = ke_info_list; ki; ki = ki->next)
+                {
+                    if (!ki->queue && ki->pid != -1)
+                    {
+                        if (!(ki->queue = str_queue_mk ()))
+                        {
+                            gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, module,
+                                    "str_queue_mk");
+                            exit (1);
+                        }
+                        str_queue_enq (ki->queue, "stop\n");
+                        str_queue_enq (ki->queue, "\001");
+                        gw_log (GW_LOG_DEBUG, module, "Stopping %d", ki->id);
+                        deliver (argc, argv, ki->id, ki->queue, &ki->gip,
+                                 &ki->pid, 1);
+                        str_queue_rm (&ki->queue);
+                        break;
+                    }
+                }
             }
+#endif
             FD_ZERO (&set_r);
             FD_SET (gip_m_fd, &set_r);
             gw_log (GW_LOG_DEBUG, module, "set gip_m_fd %d", gip_m_fd);
@@ -431,6 +463,7 @@ static void monitor_events (int argc, char **argv)
                         gipc_close (ki->gip);
                         gipc_destroy (ki->gip);
                         ki->gip = NULL;
+                        --no_process;
                     }
                     else if ((fd = gip_infileno (ki->gip)) != -1)
                     {                    /* read select on child FIFO */
@@ -475,6 +508,7 @@ static void monitor_events (int argc, char **argv)
                         gipc_close (ki->gip);
                         gipc_destroy (ki->gip);
                         ki->gip = NULL;
+                        --no_process;
                     }
                 }
            }
@@ -555,7 +589,7 @@ int main (int argc, char **argv)
     signal (SIGHUP, catch_hup);
     signal (SIGTERM, catch_term);
     signal (SIGINT, catch_int);
-#if 0
+#if 1
     gw_log_file (GW_LOG_ALL, "monitor.log");
 #endif
     monitor_events (argc, argv);