From 97d62ebf41ad027327caf69db18123e7791a9416 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 1 May 1995 12:43:26 +0000 Subject: [PATCH] First work on resource monitor program. --- kernel/Makefile | 25 +++-- kernel/eti.c | 30 +++++- kernel/lgets.c | 42 ++++++++ kernel/main.c | 7 +- kernel/monitor.c | 280 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ kernel/urp.c | 31 +----- 6 files changed, 375 insertions(+), 40 deletions(-) create mode 100644 kernel/lgets.c create mode 100644 kernel/monitor.c diff --git a/kernel/Makefile b/kernel/Makefile index 5686bc5..6fdbf04 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -2,7 +2,10 @@ # Europagate, 1995 # # $Log: Makefile,v $ -# Revision 1.21 1995/04/20 16:10:45 adam +# Revision 1.22 1995/05/01 12:43:26 adam +# First work on resource monitor program. +# +# Revision 1.21 1995/04/20 16:10:45 adam # Modified to work with non-blocking zass-api. Not using non-blocking # facility yet. # @@ -82,23 +85,31 @@ ZLIB=../../yaz/lib/libyaz.a INCLUDE=-I../include #CFLAGS=-g -Wall CPP=$(CC) -E -DEFS=$(INCLUDE) -DUSE_FML=1 -USELIBS1=../lib/ccl.a ../lib/fml.a ../lib/libzass.a ../lib/libres+log.a \ -../lib/util.a $(ZLIB) $(REGEXOBJ) +DEFS=$(INCLUDE) -DUSE_FML=1 -DUSE_MONITOR=1 PROG1=kernel O1=main.o urp.o persist.o +USELIBS1=../lib/ccl.a ../lib/fml.a ../lib/libzass.a ../lib/libres+log.a \ +../lib/util.a $(ZLIB) $(REGEXOBJ) PROG2=eti O2=eti.o +USELIBS2=../lib/libres+log.a ../lib/util.a + +PROG3=monitor +O3=monitor.o +USELIBS3=../lib/libres+log.a ../lib/util.a -all: $(PROG1) $(PROG2) +all: $(PROG1) $(PROG2) $(PROG3) $(PROG1): $(O1) $(USELIBS1) $(CC) $(CFLAGS) -o $(PROG1) $(O1) $(USELIBS1) $(NETLIB) -$(PROG2): $(O2) $(USELIBS1) - $(CC) $(CFLAGS) -o $(PROG2) $(O2) $(USELIBS1) $(NETLIB) +$(PROG2): $(O2) $(USELIBS2) + $(CC) $(CFLAGS) -o $(PROG2) $(O2) $(USELIBS2) $(NETLIB) + +$(PROG3): $(O3) $(USELIBS3) + $(CC) $(CFLAGS) -o $(PROG3) $(O3) $(USELIBS3) $(NETLIB) .c.o: $(CC) -c $(DEFS) $(CFLAGS) $< diff --git a/kernel/eti.c b/kernel/eti.c index 32e03d3..5dc1a7d 100644 --- a/kernel/eti.c +++ b/kernel/eti.c @@ -2,7 +2,10 @@ * Europagate, 1995 * * $Log: eti.c,v $ - * Revision 1.9 1995/04/21 16:37:43 adam + * 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 * Parent (eti) creates BOTH FIFOs. dtbsun is more happy now. * * Revision 1.8 1995/04/20 15:12:24 adam @@ -82,6 +85,7 @@ static int email_header (struct str_queue *sq, return 1; } +#if !USE_MONITOR static void start_kernel (int argc, char **argv, int id) { pid_t pid; @@ -116,13 +120,13 @@ static void start_kernel (int argc, char **argv, int id) exit (1); } } +#endif -static void deliver (struct str_queue *sq, GIP gip) +static void deliver (struct str_queue *sq, GIP gip, const char *msg) { int index = 0; - char *msg; - gip_wline (gip, "mail\n"); + gip_wline (gip, msg); while ((msg = str_queue_get (sq, index++))) gip_wline (gip, msg); gip_wline (gip, "\001"); @@ -133,6 +137,7 @@ int main (int argc, char **argv) char from_str[LINE_MAX+1]; char subject_str[LINE_MAX+1]; char line_str[LINE_MAX+1]; + char msg[20]; GW_DB user_db; GIP gip; void *user_info; @@ -190,8 +195,13 @@ int main (int argc, char **argv) gw_log (GW_LOG_FATAL, module, "gw_db_lookup fail"); exit (1); } +#if USE_MONITOR + sprintf (fifo_server_name, "fifo.s"); + sprintf (fifo_client_name, "fifo.c"); +#else sprintf (fifo_server_name, "fifo.s.%d", id); sprintf (fifo_client_name, "fifo.c.%d", id); +#endif gip = gipc_initialize (fifo_client_name); @@ -204,6 +214,10 @@ int main (int argc, char **argv) r = gipc_open (gip, fifo_server_name, 0); else if (pass == 2) { +#if USE_MONITOR + gw_log (GW_LOG_FATAL, module, "Cannot contact monitor"); + exit (1); +#else #if 0 gipc_close (gip); gipc_destroy (gip); @@ -219,6 +233,7 @@ int main (int argc, char **argv) { gw_log (GW_LOG_FATAL, module, "Cannot start kernel"); exit (1); +#endif } if (r < 0) if (r == -2) @@ -238,7 +253,12 @@ int main (int argc, char **argv) } /* deliver message ... */ gw_log (GW_LOG_DEBUG, module, "Delivering mail"); - deliver (queue, gip); +#if USE_MONITOR + sprintf (msg, "eti %d\n", id); +#else + strcpy (msg, "mail\n"); +#endif + deliver (queue, gip, msg); gw_log (GW_LOG_DEBUG, module, "Closing"); gipc_close (gip); gipc_destroy (gip); diff --git a/kernel/lgets.c b/kernel/lgets.c new file mode 100644 index 0000000..5e43630 --- /dev/null +++ b/kernel/lgets.c @@ -0,0 +1,42 @@ +/* Utility: Read line from FIFO + * Europagate, 1995 + * + * $Log: lgets.c,v $ + * Revision 1.1 1995/05/01 12:43:31 adam + * First work on resource monitor program. + * + */ + +#include +#include +#include +#include +#include + +#include + +int lgets (char *buf, int max, int fd) +{ + int r, no = 0; + + --max; + while (no <= max) + { + if ((r=read (fd, buf+no, 1)) != 1) + { + if (r == -1) + gw_log (GW_LOG_WARN|GW_LOG_ERRNO, "lgets", "read fail"); + else + gw_log (GW_LOG_WARN, "lgets", "read eof"); + buf[no] = '\0'; + return 0; + } + if (buf[no] == 1) + return 0; + if (buf[no++] == '\n') + break; + } + buf[no] = '\0'; + return 1; +} + diff --git a/kernel/main.c b/kernel/main.c index 374ca49..0825d96 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -2,7 +2,10 @@ * Europagate, 1995 * * $Log: main.c,v $ - * Revision 1.19 1995/04/19 16:01:58 adam + * 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. * @@ -145,7 +148,7 @@ 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); diff --git a/kernel/monitor.c b/kernel/monitor.c new file mode 100644 index 0000000..d985fce --- /dev/null +++ b/kernel/monitor.c @@ -0,0 +1,280 @@ +/* Gateway Resource Monitor + * Europagate, 1995 + * + * $Log: monitor.c,v $ + * Revision 1.1 1995/05/01 12:43:36 adam + * First work on resource monitor program. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#define LINE_MAX 1024 + +static char *module = "monitor"; +static jmp_buf retry_jmp; + +struct ke_info { + int pid; + int id; + GIP gip; + struct str_queue *queue; + struct ke_info *next; +}; + +struct ke_info *ke_info_list = NULL; + +struct ke_info *ke_info_add (int id) +{ + struct ke_info **kip; + + for (kip = &ke_info_list; *kip; kip= &(*kip)->next) + if ((*kip)->id == id) + return *kip; + *kip = malloc (sizeof(**kip)); + assert (*kip); + (*kip)->next = NULL; + (*kip)->id = id; + (*kip)->gip = NULL; + if (!((*kip)->queue = str_queue_mk ())) + { + gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, module, "str_queue_mk"); + exit (1); + } + return *kip; +} + +void ke_info_del (void) +{ + struct ke_info *ki; + + assert (ke_info_list); + ki = ke_info_list; + str_queue_rm (&ki->queue); + ke_info_list = ki->next; + free (ki); +} + +static void pipe_handle (int dummy) +{ + longjmp (retry_jmp, 1); +} + +static pid_t start_kernel (int argc, char **argv, int id) +{ + pid_t pid; + int i; + char **argv_p; + char userid_option[20]; + + argv_p = malloc (sizeof(*argv_p)*(argc+2)); + if (!argv_p) + { + gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, module, "malloc fail"); + exit (1); + } + argv_p[0] = "kernel"; + for (i = 1; inext) + { + if (!ki->queue) + continue; + 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); + } + 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); + 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) + { + gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, module, "select"); + exit (1); + } + if (FD_ISSET (gip_m_fd, &set_r)) + { + if (!(lgets (command, sizeof(command)-1, gip_m_fd))) + { + gw_log (GW_LOG_FATAL, module, "Unexpected close"); + exit (1); + } + if ((cp = strchr (command, '\n'))) + *cp = '\0'; + gw_log (GW_LOG_DEBUG, module, "IPC: %s", command); + if (!memcmp (command, "eti ", 4)) + { + 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); + 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; + } + } + } + } +} + +int main (int argc, char **argv) +{ + gw_log_init (*argv); + gw_log_level (GW_LOG_ALL); + gw_log_file (GW_LOG_ALL, "monitor.log"); + + monitor_events (argc, argv); + exit (0); +} + diff --git a/kernel/urp.c b/kernel/urp.c index ed79aca..d052151 100644 --- a/kernel/urp.c +++ b/kernel/urp.c @@ -2,7 +2,10 @@ * Europagate, 1995 * * $Log: urp.c,v $ - * Revision 1.30 1995/04/20 16:10:47 adam + * Revision 1.31 1995/05/01 12:43:38 adam + * First work on resource monitor program. + * + * Revision 1.30 1995/04/20 16:10:47 adam * Modified to work with non-blocking zass-api. Not using non-blocking * facility yet. * @@ -111,6 +114,7 @@ #include #include +#include #include #include #include "kernel.h" @@ -123,31 +127,6 @@ static void put_esc_str (const char *s) tty_emit (*s++); } -int lgets (char *buf, int max, int fd) -{ - int r, no = 0; - - --max; - while (no <= max) - { - if ((r=read (fd, buf+no, 1)) != 1) - { - if (r == -1) - gw_log (GW_LOG_WARN|GW_LOG_ERRNO, KERNEL_LOG, "read fail"); - else - gw_log (GW_LOG_WARN, KERNEL_LOG, "read eof"); - buf[no] = '\0'; - return 0; - } - if (buf[no] == 1) - return 0; - if (buf[no++] == '\n') - break; - } - buf[no] = '\0'; - return 1; -} - int reopen_target (void) { const char *v; -- 1.7.10.4