X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;f=kernel%2Fmain.c;h=a8fadfb14a7342923b5d0bd0d683f3fab5bd786d;hb=d519fdaae5ce6533cfaa65d0e9715b2bc1c8ae46;hp=10dc733cd158fcb82a0866e098e351f858b1a843;hpb=c3d25c24fb405af98c6879fa7f5f619ccc895151;p=egate.git diff --git a/kernel/main.c b/kernel/main.c index 10dc733..a8fadfb 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -1,8 +1,23 @@ -/* Gateway kernel +/* Gateway kernel - Main * Europagate, 1995 * * $Log: main.c,v $ - * Revision 1.12 1995/03/27 12:51:05 adam + * Revision 1.17 1995/04/19 10:46:18 adam + * Persistency works much better now. New command: status - history-like + * + * Revision 1.16 1995/04/19 07:31:07 adam + * First work on Z39.50 persistence. + * + * Revision 1.15 1995/04/17 09:34:30 adam + * Timeout (idletime) adjustable. Minor changes in kernel. + * + * Revision 1.14 1995/03/28 11:42:34 adam + * First use of string-queue utility. + * + * Revision 1.13 1995/03/28 08:01:25 adam + * FIFO existence is used to test for a running kernel. + * + * Revision 1.12 1995/03/27 12:51:05 adam * New log level in use: GW_LOG_ERRNO. * * Revision 1.11 1995/03/27 08:24:02 adam @@ -57,47 +72,26 @@ #include #include +#include #include "kernel.h" FILE *reply_fd = stdout; struct gw_kernel_info info; -static void mk_active (int userid) -{ - char active_name[1024]; - char pid_buf[30]; - int fd; - - sprintf (active_name, "kernel.pid.%d", userid); - fd = open (active_name, O_WRONLY|O_CREAT, 0666); - if (fd == -1) - { - gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, "Cannot create %s", active_name); - exit (1); - } - sprintf (pid_buf, "%ld", (long) getpid()); - write (fd, pid_buf, strlen(pid_buf)); - close (fd); -} - -static void rm_active (int userid) -{ - char active_name[1024]; - - sprintf (active_name, "kernel.pid.%d", userid); - unlink (active_name); -} - -static void kernel_events (int userid) +static void kernel_events (struct str_queue *queue, int userid) { char fifo_client_name[1024]; char fifo_server_name[1024]; + char line_buf[1024]; GIP gip; fd_set set_r; int r, gip_fd; struct timeval tv; + int timeout; + int continuation = 0; + timeout = atoi(gw_res_get (info.kernel_res, "gw.timeout", "600")); gw_log (GW_LOG_DEBUG, KERNEL_LOG, "kernel event loop"); sprintf (fifo_client_name, "fifo.c.%d", userid); @@ -111,7 +105,7 @@ static void kernel_events (int userid) { FD_ZERO (&set_r); FD_SET (gip_fd, &set_r); - tv.tv_sec = 60; + tv.tv_sec = timeout; tv.tv_usec = 0; gw_log (GW_LOG_DEBUG, KERNEL_LOG, "IPC select"); @@ -123,7 +117,10 @@ static void kernel_events (int userid) } if (r == 0) { - gw_log (GW_LOG_STAT, KERNEL_LOG, "Timeout"); + gw_log (GW_LOG_STAT, KERNEL_LOG, "Timeout after %d seconds", + timeout); + if (info.zass) + save_p_state (userid); break; } if (FD_ISSET (gip_fd, &set_r)) @@ -131,14 +128,25 @@ static void kernel_events (int userid) char command[128], *cp; if (!(lgets (command, 127, gip_fd))) + { + gw_log (GW_LOG_WARN, KERNEL_LOG, "Unexpected close"); break; + } if ((cp = strchr (command, '\n'))) *cp = '\0'; gw_log (GW_LOG_STAT, KERNEL_LOG, "IPC: %s", command); if (!strcmp (command, "mail")) { gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Incoming mail...\n"); - urp (gip_fd); + while (lgets (line_buf, sizeof(line_buf)-1, gip_fd)) + str_queue_enq (queue, line_buf); + urp_start (continuation, queue); + if (!continuation) + load_p_state (userid); + urp_command (queue); + urp_end (); + while (str_queue_deq (queue, 0, 0)) + ; } else if (!strcmp (command, "stop")) { @@ -149,15 +157,19 @@ static void kernel_events (int userid) { gw_log (GW_LOG_WARN, KERNEL_LOG, "Unknown IPC: %s", command); } + continuation = 1; } } gips_close (gip); gips_destroy (gip); + unlink (fifo_client_name); + unlink (fifo_server_name); } int main (int argc, char **argv) { int userid = -1; + struct str_queue *queue; info.kernel_res = NULL; info.default_res = "default.res"; @@ -170,6 +182,7 @@ int main (int argc, char **argv) info.override_hostname = NULL; info.databases = NULL; info.database = NULL; + info.setno = -1; #if USE_FML info.fml = NULL; #endif @@ -190,14 +203,17 @@ int main (int argc, char **argv) fprintf (stderr, "Options:\n"); fprintf (stderr, " -d Enable debugging log\n"); fprintf (stderr, " -t target Open target immediately\n"); - fprintf (stderr, " -l lang Set language\n"); + fprintf (stderr, " -g lang Set language\n"); fprintf (stderr, " -o resource Override with resource\n"); fprintf (stderr, " -h host Override host\n"); fprintf (stderr, " -p port Override port\n"); - fprintf (stderr, " -g log Set Log file\n"); + fprintf (stderr, " -l log Set Log file\n"); fprintf (stderr, " -i id Set IPC userid\n"); exit (1); case 'd': + gw_log_level (GW_LOG_ALL & ~RES_DEBUG); + break; + case 'D': gw_log_level (GW_LOG_ALL); break; case 't': @@ -214,7 +230,7 @@ int main (int argc, char **argv) exit (1); } break; - case 'l': + case 'g': if (argv[0][2]) info.lang = argv[0]+2; else if (argc > 0) @@ -270,7 +286,7 @@ int main (int argc, char **argv) exit (1); } break; - case 'g': + case 'l': if (argv[0][2]) gw_log_file (GW_LOG_ALL, argv[0]+2); else if (argc > 0) @@ -306,19 +322,34 @@ int main (int argc, char **argv) else info.default_res = *argv; } - read_kernel_res (); + if (!(queue = str_queue_mk ())) + { + gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, KERNEL_LOG, "str_queue_mk"); + exit (1); + } if (userid != -1) { - mk_active (userid); - kernel_events (userid); - rm_active (userid); + read_kernel_res (); + kernel_events (queue, userid); } else - urp (0); + { + char line_buf[512]; + read_kernel_res (); + while (lgets (line_buf, sizeof(line_buf)-1, 0)) + str_queue_enq (queue, line_buf); + urp_start (0, queue); + urp_command (queue); + urp_end (); + } return 0; } -struct gw_user_set *user_set_add (const char *name, int hits) +struct gw_user_set *user_set_add (const char *name, int hits, + const char *database, + struct ccl_rpn_node *rpn, + int present_flag, + const char *search_str) { struct gw_user_set *s; @@ -327,6 +358,10 @@ struct gw_user_set *user_set_add (const char *name, int hits) s->name = gw_strdup (name); s->hits = hits; + s->database = gw_strdup (database); + s->rpn = rpn; + s->present_flag = present_flag; + s->search_str = gw_strdup (search_str); s->prev = info.sets; info.sets = s; return s; @@ -339,6 +374,8 @@ void user_set_init (void) for (s = info.sets; s; s = s1) { free (s->name); + free (s->database); + ccl_rpn_delete (s->rpn); s1 = s->prev; free (s); } @@ -500,6 +537,8 @@ 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 USE_FML if (!info.fml) {