* Europagate, 1995
*
* $Log: eti.c,v $
- * Revision 1.13 1995/05/16 09:40:41 adam
+ * Revision 1.16 1995/07/11 11:49:11 adam
+ * LINE_MAX renamed to STR_LINE_MAX.
+ *
+ * Revision 1.15 1995/07/03 12:59:28 adam
+ * New option for eti: -c dir to chdir before start.
+ * Setting change: gw.max.show defaults to 100.
+ *
+ * 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
#include <gw-log.h>
#include <gw-db.h>
+#include <gw-res.h>
#include <gip.h>
#include <strqueue.h>
-#define LINE_MAX 1024
+#define STR_LINE_MAX 1024
static char *module = "eti";
static jmp_buf retry_jmp;
return 1;
}
-#if !USE_MONITOR
static void start_kernel (int argc, char **argv, int id)
{
pid_t pid;
exit (1);
}
}
-#endif
static void deliver (struct str_queue *sq, GIP gip, const char *msg)
{
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 from_str[STR_LINE_MAX+1];
+ char subject_str[STR_LINE_MAX+1];
+ char line_str[STR_LINE_MAX+1];
char msg[20];
GW_DB user_db;
GIP gip;
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, " -c dir Change to directory\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;
+ case 'c':
+ if (argv[argno][2])
+ {
+ if (chdir (argv[argno]+2))
+ gw_log (GW_LOG_WARN|GW_LOG_ERRNO, module, "chdir");
+ }
+ else if (++argno < argc)
+ {
+ if (chdir (argv[argno]))
+ gw_log (GW_LOG_WARN|GW_LOG_ERRNO, module, "chdir");
+ }
+ else
+ {
+ fprintf (stderr, "%s: missing chdir name\n", *argv);
+ exit (1);
+ }
+ 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");
exit (1);
}
- while (fgets (line_str, LINE_MAX, stdin))
+ while (fgets (line_str, STR_LINE_MAX, stdin))
str_queue_enq (queue, line_str);
r = email_header (queue, from_str, subject_str);
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);
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)
}
/* 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);