From 90577270f3555c93afd2df18c5f42dca967d57d5 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 1 May 1995 16:26:56 +0000 Subject: [PATCH] More work on resource monitor. --- kernel/eti.c | 6 ++- kernel/main.c | 11 +++-- kernel/monitor.c | 117 ++++++++++++++++++++++++++++++++++-------------------- 3 files changed, 87 insertions(+), 47 deletions(-) diff --git a/kernel/eti.c b/kernel/eti.c index 5dc1a7d..f7a1b99 100644 --- a/kernel/eti.c +++ b/kernel/eti.c @@ -2,7 +2,10 @@ * Europagate, 1995 * * $Log: eti.c,v $ - * Revision 1.10 1995/05/01 12:43:29 adam + * Revision 1.11 1995/05/01 16:26:56 adam + * More work on resource monitor. + * + * Revision 1.10 1995/05/01 12:43:29 adam * First work on resource monitor program. * * Revision 1.9 1995/04/21 16:37:43 adam @@ -225,6 +228,7 @@ int main (int argc, char **argv) unlink (fifo_client_name); gip = gipc_initialize (fifo_client_name); #endif + mknod (fifo_server_name, S_IFIFO|0666, 0); start_kernel (argc, argv, id); r = gipc_open (gip, fifo_server_name, 1); diff --git a/kernel/main.c b/kernel/main.c index 0825d96..63d6a4f 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -2,7 +2,10 @@ * Europagate, 1995 * * $Log: main.c,v $ - * Revision 1.20 1995/05/01 12:43:32 adam + * 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 @@ -100,9 +103,10 @@ static void kernel_events (struct str_queue *queue, int userid) struct timeval tv; int timeout; int continuation = 0; + int extra_fd; timeout = atoi(gw_res_get (info.kernel_res, "gw.timeout", "600")); - gw_log (GW_LOG_DEBUG, KERNEL_LOG, "kernel event loop"); + 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); @@ -110,7 +114,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) { @@ -171,6 +175,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); diff --git a/kernel/monitor.c b/kernel/monitor.c index d985fce..43c9aec 100644 --- a/kernel/monitor.c +++ b/kernel/monitor.c @@ -2,7 +2,10 @@ * Europagate, 1995 * * $Log: monitor.c,v $ - * Revision 1.1 1995/05/01 12:43:36 adam + * Revision 1.2 1995/05/01 16:26:57 adam + * More work on resource monitor. + * + * Revision 1.1 1995/05/01 12:43:36 adam * First work on resource monitor program. * */ @@ -21,6 +24,7 @@ #include #include #include +#include #include #include @@ -74,6 +78,13 @@ void ke_info_del (void) free (ki); } +static void catchchild (int num) +{ + while (waitpid (-1, 0, WNOHANG) > 0) + ; + signal (SIGCHLD, catchchild); +} + static void pipe_handle (int dummy) { longjmp (retry_jmp, 1); @@ -194,42 +205,76 @@ static void monitor_events (int argc, char **argv) struct ke_info *ki; FD_ZERO (&set_r); - FD_SET (gip_m_fd, &set_r); - fd_max = gip_m_fd; - - for (ki = ke_info_list; ki; ki = ki->next) - { - if (!ki->queue) + FD_SET (gip_m_fd, &set_r); + gw_log (GW_LOG_DEBUG, module, "set r %d", gip_m_fd); + fd_max = gip_m_fd; + + for (ki = ke_info_list; ki; ki = ki->next) + { + if (!ki->queue) continue; - gw_log (GW_LOG_DEBUG, module, "Transfer mail to %d", ki->id); + gw_log (GW_LOG_DEBUG, module, "Transfer mail to %d", ki->id); deliver (argc, argv, ki->id, ki->queue, &ki->gip); - str_queue_rm (&ki->queue); + str_queue_rm (&ki->queue); } - for (ki = ke_info_list; ki; ki = ki->next) - { - int fd; + for (ki = ke_info_list; ki; ki = ki->next) + { + int fd; if (ki->gip && (fd = gip_infileno (ki->gip)) != -1) - { - gw_log (GW_LOG_DEBUG, module, "set r %d", fd); + { + gw_log (GW_LOG_DEBUG, module, "set r %d", fd); FD_SET (fd, &set_r); if (fd > fd_max) fd_max = fd; - } - } - gw_log (GW_LOG_DEBUG, module, "Monitor select"); - r = select (fd_max+1, &set_r, NULL, NULL, NULL); - if (r == -1) + } + } + while (1) + { + gw_log (GW_LOG_DEBUG, module, "IPC select"); + r = select (fd_max+1, &set_r, NULL, NULL, NULL); + if (r != -1) + break; + if (errno != EINTR) + { + gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, module, "select"); + exit (1); + } + gw_log (GW_LOG_DEBUG|GW_LOG_ERRNO, module, "select"); + } + gw_log (GW_LOG_DEBUG, module, "Testing ke_info_list"); + for (ki = ke_info_list; ki; ki = ki->next) { - gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, module, "select"); - exit (1); + int fd; + if (ki->gip && (fd = gip_infileno (ki->gip)) != -1) + { + gw_log (GW_LOG_DEBUG, module, "Test of %d", fd); + if (FD_ISSET (fd, &set_r)) + { + if (lgets (line_buf, sizeof(line_buf)-1, fd)) + { + gw_log (GW_LOG_DEBUG, module, "IPC: %s", line_buf); + } + else + { + gw_log (GW_LOG_DEBUG, module, "Close of %d", ki->id); + gipc_close (ki->gip); + gipc_destroy (ki->gip); + ki->gip = NULL; + } + } + } } + + gw_log (GW_LOG_DEBUG, module, "Testing gip_m_fd %d", gip_m_fd); if (FD_ISSET (gip_m_fd, &set_r)) { + gw_log (GW_LOG_DEBUG, module, "Reading from %d", gip_m_fd); if (!(lgets (command, sizeof(command)-1, gip_m_fd))) { gw_log (GW_LOG_FATAL, module, "Unexpected close"); exit (1); } + gw_log (GW_LOG_DEBUG, module, "Done"); if ((cp = strchr (command, '\n'))) *cp = '\0'; gw_log (GW_LOG_DEBUG, module, "IPC: %s", command); @@ -237,34 +282,15 @@ static void monitor_events (int argc, char **argv) { int id = atoi (command+4); struct ke_info *new_k; - + new_k = ke_info_add (id); - gw_log (GW_LOG_DEBUG, "module", "Incoming mail %d", id); + gw_log (GW_LOG_DEBUG, module, "Incoming mail %d", id); str_queue_enq (new_k->queue, "mail\n"); while (lgets (line_buf, sizeof(line_buf)-1, gip_m_fd)) str_queue_enq (new_k->queue, line_buf); str_queue_enq (new_k->queue, "\001"); } } - for (ki = ke_info_list; ki; ki = ki->next) - { - int fd; - if (ki->gip && (fd = gip_infileno (ki->gip)) != -1 && - FD_ISSET (fd, &set_r)) - { - if (lgets (line_buf, sizeof(line_buf)-1, fd)) - { - gw_log (GW_LOG_DEBUG, module, "IPC: %s", line_buf); - } - else - { - gw_log (GW_LOG_DEBUG, module, "Close of %d", ki->id); - gipc_close (ki->gip); - gipc_destroy (ki->gip); - ki->gip = NULL; - } - } - } } } @@ -272,9 +298,14 @@ int main (int argc, char **argv) { gw_log_init (*argv); gw_log_level (GW_LOG_ALL); +#if 0 + signal (SIGCHLD, catchchild); gw_log_file (GW_LOG_ALL, "monitor.log"); - +#endif monitor_events (argc, argv); exit (0); } + + + -- 1.7.10.4