From aa975e8f85af258357639e3407ce40090f4a4998 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 19 May 1995 13:25:58 +0000 Subject: [PATCH] Bug fixes. Better command line options. --- kernel/Makefile | 7 +++- kernel/default.res | 6 +-- kernel/eti.c | 107 ++++++++++++++++++++++++++++++++++++---------------- kernel/main.c | 36 +++++++++++------- kernel/monitor.c | 54 +++++++++++++++++++------- kernel/persist.c | 10 +++-- kernel/urp.c | 7 ++-- 7 files changed, 155 insertions(+), 72 deletions(-) diff --git a/kernel/Makefile b/kernel/Makefile index a3bd605..1bb7c82 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -2,7 +2,10 @@ # Europagate, 1995 # # $Log: Makefile,v $ -# Revision 1.24 1995/05/03 12:18:46 adam +# Revision 1.25 1995/05/19 13:25:58 adam +# Bug fixes. Better command line options. +# +# Revision 1.24 1995/05/03 12:18:46 adam # This code ran on dtbsun. Minor changes. # # Revision 1.23 1995/05/03 07:37:29 adam @@ -92,7 +95,7 @@ ZLIB=../../yaz/lib/libyaz.a INCLUDE=-I../include #CFLAGS=-g -Wall CPP=$(CC) -E -DEFS=$(INCLUDE) -DUSE_FML=1 -DUSE_MONITOR=1 +DEFS=$(INCLUDE) -DUSE_FML=1 PROG1=kernel O1=main.o urp.o persist.o diff --git a/kernel/default.res b/kernel/default.res index f69b903..539a918 100644 --- a/kernel/default.res +++ b/kernel/default.res @@ -1,13 +1,13 @@ # Email gateway - general kernel resources -# $Id: default.res,v 1.22 1995/05/17 10:51:32 adam Exp $ +# $Id: default.res,v 1.23 1995/05/19 13:25:58 adam Exp $ # # Important directories, programs, etc. -gw.reply.mta: /usr/lib/sendmail +gw.reply.mta: /usr/lib/sendmailx gw.reply.tmp.prefix: gwr gw.reply.tmp.dir: /tmp #gw.path: /home/adam/egate/kernel gw.marc.log: marc.log -gw.timeout: 5 +gw.timeout: 30 gw.resultset: 1 gw.persist: 1 gw.max.process: 3 diff --git a/kernel/eti.c b/kernel/eti.c index f5a8b0f..48178a0 100644 --- a/kernel/eti.c +++ b/kernel/eti.c @@ -45,7 +45,10 @@ * Europagate, 1995 * * $Log: eti.c,v $ - * Revision 1.13 1995/05/16 09:40:41 adam + * Revision 1.14 1995/05/19 13:25:59 adam + * Bug fixes. Better command line options. + * + * Revision 1.13 1995/05/16 09:40:41 adam * LICENSE. Setting of CCL token names (and/or/not/set) in read_kernel_res. * * Revision 1.12 1995/05/03 07:37:35 adam @@ -104,6 +107,7 @@ #include #include +#include #include #include @@ -138,7 +142,6 @@ 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; @@ -173,7 +176,6 @@ static void start_kernel (int argc, char **argv, int id) exit (1); } } -#endif static void deliver (struct str_queue *sq, GIP gip, const char *msg) { @@ -201,11 +203,55 @@ int main (int argc, char **argv) char fifo_client_name[1024]; char fifo_server_name[1024]; struct str_queue *queue; + int monitor_flag = 1; + int argno = 0; gw_log_init (*argv); - gw_log_level (GW_LOG_ALL); - gw_log_file (GW_LOG_ALL, "eti.log"); - + while (++argno < argc) + { + if (argv[argno][0] == '-') + { + if (argv[argno][1] == '-') + { + monitor_flag = 0; + break; + } + switch (argv[argno][1]) + { + case 'h': + case 'H': + fprintf (stderr, "eti [options] -- [kernelOptions]\n"); + fprintf (stderr, "Options:\n"); + fprintf (stderr, " -l log Set Log file\n"); + fprintf (stderr, " -d Enable debugging log\n"); + fprintf (stderr, " -D Enable more debugging log\n"); + fprintf (stderr, " -- Precedes kernel options " + "(kernel is invoked instead of monitor)\n"); + exit (1); + case 'l': + if (argv[argno][2]) + gw_log_file (GW_LOG_ALL, argv[argno]+2); + else if (++argno < argc) + gw_log_file (GW_LOG_ALL, argv[argno]); + else + { + fprintf (stderr, "%s: missing log filename\n", *argv); + exit (1); + } + break; + case 'd': + gw_log_level (GW_LOG_ALL & ~RES_DEBUG); + break; + case 'D': + gw_log_level (GW_LOG_ALL); + break; + default: + fprintf (stderr, "%s: unknown option `%s'; use -H for help\n", + *argv, argv[argno]); + exit (1); + } + } + } if (!(queue = str_queue_mk ())) { gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, module, "str_queue_mk"); @@ -248,13 +294,16 @@ 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.m"); - sprintf (fifo_client_name, "fifo.c.m"); -#else - sprintf (fifo_server_name, "fifo.s.%d", id); - sprintf (fifo_client_name, "fifo.c.%d", id); -#endif + if (monitor_flag) + { + sprintf (fifo_server_name, "fifo.s.m"); + sprintf (fifo_client_name, "fifo.c.m"); + } + else + { + sprintf (fifo_server_name, "fifo.s.%d", id); + sprintf (fifo_client_name, "fifo.c.%d", id); + } gip = gipc_initialize (fifo_client_name); @@ -264,30 +313,25 @@ int main (int argc, char **argv) signal (SIGPIPE, pipe_handle); gw_log (GW_LOG_DEBUG, module, "Pass %d", pass); if (pass == 1) + { + gipc_close (gip); 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); - unlink (fifo_server_name); - unlink (fifo_client_name); - gip = gipc_initialize (fifo_client_name); -#endif - + if (monitor_flag) + { + gw_log (GW_LOG_FATAL, module, "Cannot contact monitor"); + exit (1); + } mknod (fifo_server_name, S_IFIFO|0666, 0); - start_kernel (argc, argv, id); + start_kernel (argc-argno, argv+argno, id); r = gipc_open (gip, fifo_server_name, 1); } else if (pass == 3) { gw_log (GW_LOG_FATAL, module, "Cannot start kernel"); exit (1); -#endif } if (r < 0) if (r == -2) @@ -307,11 +351,10 @@ int main (int argc, char **argv) } /* deliver message ... */ gw_log (GW_LOG_DEBUG, module, "Delivering mail"); -#if USE_MONITOR - sprintf (msg, "eti %d\n", id); -#else - strcpy (msg, "mail\n"); -#endif + if (monitor_flag) + sprintf (msg, "eti %d\n", id); + else + strcpy (msg, "mail\n"); deliver (queue, gip, msg); gw_log (GW_LOG_DEBUG, module, "Closing"); gipc_close (gip); diff --git a/kernel/main.c b/kernel/main.c index 0f511c7..5ed778e 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -45,7 +45,10 @@ * Europagate, 1995 * * $Log: main.c,v $ - * Revision 1.26 1995/05/18 12:03:08 adam + * Revision 1.27 1995/05/19 13:25:59 adam + * Bug fixes. Better command line options. + * + * Revision 1.26 1995/05/18 12:03:08 adam * Bug fixes and minor improvements. * * Revision 1.25 1995/05/16 09:40:42 adam @@ -164,6 +167,7 @@ static void kernel_events (struct str_queue *queue) int continuation = 0; int extra_fd; int persist_flag; + int stop_flag = 0; persist_flag = gw_res_bool (info.kernel_res, "gw.persist", 0); timeout = gw_res_int (info.kernel_res, "gw.timeout", 600); @@ -173,7 +177,7 @@ static void kernel_events (struct str_queue *queue) sprintf (fifo_server_name, "fifo.s.%d", info.userid); gip = gips_initialize (fifo_server_name); - gips_open (gip, fifo_client_name); + gips_open (gip, fifo_client_name, 1); gip_fd = gip_infileno (gip); extra_fd = open (fifo_server_name, O_WRONLY); @@ -181,7 +185,10 @@ static void kernel_events (struct str_queue *queue) { FD_ZERO (&set_r); FD_SET (gip_fd, &set_r); - tv.tv_sec = timeout; + if (stop_flag) + tv.tv_sec = 1; + else + tv.tv_sec = timeout; tv.tv_usec = 0; gw_log (GW_LOG_DEBUG, KERNEL_LOG, "IPC select"); @@ -193,8 +200,11 @@ static void kernel_events (struct str_queue *queue) } if (r == 0) { - gw_log (GW_LOG_STAT, KERNEL_LOG, "Timeout after %d seconds", - timeout); + if (stop_flag) + gw_log (GW_LOG_STAT, KERNEL_LOG, "Stopping"); + else + gw_log (GW_LOG_STAT, KERNEL_LOG, "Timeout after %d seconds", + timeout); if (info.zass && persist_flag) save_p_state (info.userid); break; @@ -235,21 +245,18 @@ static void kernel_events (struct str_queue *queue) else if (!strcmp (command, "stop")) { gw_log (GW_LOG_DEBUG, KERNEL_LOG, "stop"); - break; + while (lgets (line_buf, sizeof(line_buf)-1, gip_fd)) + ; + break; } else - { gw_log (GW_LOG_WARN, KERNEL_LOG, "Unknown IPC: %s", command); - } continuation = 1; } } close (extra_fd); gips_close (gip); gips_destroy (gip); - - unlink (fifo_client_name); - unlink (fifo_server_name); } int main (int argc, char **argv) @@ -284,8 +291,8 @@ int main (int argc, char **argv) switch (argv[0][1]) { case 'H': - fprintf (stderr, "kernel [option..] [resource]\n"); - fprintf (stderr, "If no resource file is given"); + fprintf (stderr, "kernel [options] [resourceFile]\n"); + fprintf (stderr, "If no resource file is specified"); fprintf (stderr, " default.res is used\n"); fprintf (stderr, "Options:\n"); fprintf (stderr, " -d Enable debugging log\n"); @@ -403,7 +410,8 @@ int main (int argc, char **argv) gw_log_session (info.userid); break; default: - gw_log (GW_LOG_FATAL, KERNEL_LOG, "unknown option %s", *argv); + gw_log (GW_LOG_FATAL, KERNEL_LOG, "unknown option %s;" + " use -H for help", *argv); exit (1); } } diff --git a/kernel/monitor.c b/kernel/monitor.c index aeb5cb7..8982094 100644 --- a/kernel/monitor.c +++ b/kernel/monitor.c @@ -45,7 +45,10 @@ * Europagate, 1995 * * $Log: monitor.c,v $ - * Revision 1.10 1995/05/18 12:03:09 adam + * Revision 1.11 1995/05/19 13:26:00 adam + * Bug fixes. Better command line options. + * + * Revision 1.10 1995/05/18 12:03:09 adam * Bug fixes and minor improvements. * * Revision 1.9 1995/05/17 10:51:32 adam @@ -376,10 +379,11 @@ static void monitor_events (int argc, char **argv) fd_set set_r; char command[128], *cp; + mknod (MONITOR_FIFO_C, S_IFIFO|0666, 0); + open (MONITOR_FIFO_C, O_RDONLY|O_NONBLOCK); gip_m = gips_initialize (MONITOR_FIFO_S); - r = gips_open (gip_m, MONITOR_FIFO_C); + r = gips_open (gip_m, MONITOR_FIFO_C, 0); gip_m_fd = gip_infileno (gip_m); - open (MONITOR_FIFO_S, O_WRONLY); while (1) { @@ -444,9 +448,11 @@ static void monitor_events (int argc, char **argv) } 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); + r = deliver (argc, argv, ki->id, ki->queue, &ki->gip, + &ki->pid, 1); + if (r != 1) + gw_log (GW_LOG_DEBUG, module, + "Stop not sent: %d", r); str_queue_rm (&ki->queue); break; } @@ -569,20 +575,44 @@ int main (int argc, char **argv) { if (argv[argno][0] == '-') { + if (argv[argno][1] == '-') + break; switch (argv[argno][1]) { + case 'h': case 'H': - fprintf (stderr, "monitor [option..] [resource]\n"); - fprintf (stderr, "If no resource file is given"); + fprintf (stderr, "monitor [options] [resourceFile]" + " -- [kernelOptions]\n"); + fprintf (stderr, "If no resource file is specified"); fprintf (stderr, " default.res is used\n"); - fprintf (stderr, "Options are transferred to kernel\n"); + fprintf (stderr, "Options:\n"); + fprintf (stderr, " -l log Set Log file\n"); + fprintf (stderr, " -d Enable debugging log\n"); + fprintf (stderr, " -D Enable more debugging log\n"); + fprintf (stderr, " -- Precedes kernel options\n"); + fprintf (stderr, "Kernel options are transferred to kernel\n"); exit (1); + case 'l': + if (argv[argno][2]) + gw_log_file (GW_LOG_ALL, argv[argno]+2); + else if (++argno < argc) + gw_log_file (GW_LOG_ALL, argv[argno]); + else + { + fprintf (stderr, "%s: missing log filename\n", *argv); + exit (1); + } + break; case 'd': gw_log_level (GW_LOG_ALL & ~RES_DEBUG); break; case 'D': gw_log_level (GW_LOG_ALL); break; + default: + fprintf (stderr, "%s: unknown option `%s'; use -H for help\n", + *argv, argv[argno]); + exit (1); } } else @@ -593,10 +623,6 @@ int main (int argc, char **argv) signal (SIGHUP, catch_hup); signal (SIGTERM, catch_term); signal (SIGINT, catch_int); -#if 1 - gw_log_level (GW_LOG_ALL & ~RES_DEBUG); - gw_log_file (GW_LOG_ALL, "monitor.log"); -#endif - monitor_events (argc, argv); + monitor_events (argc-argno, argv+argno); exit (0); } diff --git a/kernel/persist.c b/kernel/persist.c index 4d989e6..8daeaca 100644 --- a/kernel/persist.c +++ b/kernel/persist.c @@ -45,7 +45,10 @@ * Europagate, 1995 * * $Log: persist.c,v $ - * Revision 1.8 1995/05/16 09:40:43 adam + * Revision 1.9 1995/05/19 13:26:00 adam + * Bug fixes. Better command line options. + * + * Revision 1.8 1995/05/16 09:40:43 adam * LICENSE. Setting of CCL token names (and/or/not/set) in read_kernel_res. * * Revision 1.7 1995/05/03 16:34:19 adam @@ -297,9 +300,6 @@ int load_p_state (int userid) return -1; gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Reading persistence file %s (2)", fname); -#if 0 - reopen_target (); -#endif while (fgetsx (fline, 1024, inf)) { gw_log (GW_LOG_DEBUG, KERNEL_LOG, @@ -314,7 +314,9 @@ int load_p_state (int userid) gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Search string %s", fline); set = user_set_add (resultname, hits, database, NULL, 0, fline); set->rpn = load_rpn (fline, inf); +#if 0 ccl_pr_tree (set->rpn, stderr); +#endif fgetsx (fline, 1024, inf); } fclose (inf); diff --git a/kernel/urp.c b/kernel/urp.c index 820a39b..90b5cd1 100644 --- a/kernel/urp.c +++ b/kernel/urp.c @@ -45,7 +45,10 @@ * Europagate, 1995 * * $Log: urp.c,v $ - * Revision 1.37 1995/05/18 12:03:09 adam + * Revision 1.38 1995/05/19 13:26:00 adam + * Bug fixes. Better command line options. + * + * Revision 1.37 1995/05/18 12:03:09 adam * Bug fixes and minor improvements. * * Revision 1.36 1995/05/17 10:51:33 adam @@ -1130,14 +1133,12 @@ void urp_end (void) mta = gw_res_get (info.kernel_res, "gw.reply.mta", "/usr/lib/sendmail"); sprintf (cmd, "%s %s < %s", mta, info.from_str, info.reply_fname); -#if 0 mta_code = system (cmd); if (mta_code) gw_log (GW_LOG_FATAL, KERNEL_LOG, "Reply '%s' got exit code %d", cmd, mta_code); else unlink (info.reply_fname); -#endif gw_log (GW_LOG_ACCT, KERNEL_LOG, "User end %s", info.from_str); } } -- 1.7.10.4