X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=kernel%2Fmain.c;h=9398e2b22293a1d0e4e836821869d2c56db75fbd;hb=7d911b772d7116575f2537b48005ad873fde4473;hp=fd6ef7ef2ca07ce6761d17a0ce13c1d277c243b7;hpb=43c5b3372d7c17b2c196e90115fb6058b813b003;p=egate.git diff --git a/kernel/main.c b/kernel/main.c index fd6ef7e..9398e2b 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -1,8 +1,14 @@ -/* Gateway kernel +/* Gateway kernel - Main * Europagate, 1995 * * $Log: main.c,v $ - * Revision 1.13 1995/03/28 08:01:25 adam + * 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 @@ -60,21 +66,26 @@ #include #include +#include #include "kernel.h" FILE *reply_fd = stdout; struct gw_kernel_info info; -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); @@ -88,7 +99,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"); @@ -100,7 +111,8 @@ 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); break; } if (FD_ISSET (gip_fd, &set_r)) @@ -118,7 +130,13 @@ static void kernel_events (int userid) 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); + urp_command (queue); + urp_end (); + while (str_queue_deq (queue, 0, 0)) + ; } else if (!strcmp (command, "stop")) { @@ -129,6 +147,7 @@ static void kernel_events (int userid) { gw_log (GW_LOG_WARN, KERNEL_LOG, "Unknown IPC: %s", command); } + continuation = 1; } } gips_close (gip); @@ -140,6 +159,7 @@ static void kernel_events (int userid) int main (int argc, char **argv) { int userid = -1; + struct str_queue *queue; info.kernel_res = NULL; info.default_res = "default.res"; @@ -172,11 +192,11 @@ 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': @@ -196,7 +216,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) @@ -252,7 +272,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) @@ -289,10 +309,22 @@ int main (int argc, char **argv) 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) - kernel_events (userid); + kernel_events (queue, userid); else - urp (0); + { + char line_buf[512]; + 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; }