-/* Gateway kernel
+/* Gateway Email Transport Interface
* Europagate, 1995
*
* $Log: eti.c,v $
- * Revision 1.3 1995/03/28 08:01:23 adam
+ * Revision 1.12 1995/05/03 07:37:35 adam
+ * CCL commands stop/continue implemented. New functions gw_res_{int,bool}
+ * are used when possible.
+ *
+ * Revision 1.11 1995/05/01 16:26:56 adam
+ * More work on resource monitor.
+ *
+ * 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
+ * Minor hacks really.
+ *
+ * Revision 1.7 1995/04/19 16:01:57 adam
+ * Some hacks to get the FIFO communication work!! Isn't reliable.
+ * Resource gw.account added - default account info.
+ *
+ * Revision 1.6 1995/04/17 09:34:27 adam
+ * Timeout (idletime) adjustable. Minor changes in kernel.
+ *
+ * Revision 1.5 1995/03/31 09:43:13 adam
+ * Removed unused variable.
+ *
+ * Revision 1.4 1995/03/28 11:42:34 adam
+ * First use of string-queue utility.
+ *
+ * Revision 1.3 1995/03/28 08:01:23 adam
* FIFO existence is used to test for a running kernel.
*
* Revision 1.2 1995/03/27 12:51:05 adam
#include <setjmp.h>
#include <signal.h>
+#include <sys/file.h>
+#include <sys/stat.h>
+
#include <gw-log.h>
#include <gw-db.h>
#include <gip.h>
+#include <strqueue.h>
#define LINE_MAX 1024
-static char line_buf[LINE_MAX+1];
static char *module = "eti";
static jmp_buf retry_jmp;
longjmp (retry_jmp, 1);
}
-static int email_header (FILE *inf, char *from_str, char *subject_str)
+static int email_header (struct str_queue *sq,
+ char *from_str, char *subject_str)
{
+ char *msg;
+ int index = 0;
+
*from_str = '\0';
- *subject_str = '\0';
- while (fgets (line_buf, LINE_MAX, inf))
+ *subject_str = '\0';
+ while ((msg = str_queue_get (sq, index++)))
{
- if (line_buf[0] == '\n')
+ if (msg[0] == '\n')
return 0;
- if (strncmp (line_buf, "From ", 5) == 0)
- sscanf (line_buf+4, "%s", from_str);
- if (strncmp (line_buf, "Subject: ", 9) == 0 &&
- sscanf (line_buf+9, "%s", subject_str+1) == 1)
- strcpy (subject_str, line_buf+9);
+ if (memcmp (msg, "From ", 5) == 0)
+ sscanf (msg+4, "%s", from_str);
+ if (memcmp (msg, "Subject: ", 9) == 0 &&
+ sscanf (msg+9, "%s", subject_str+1) == 1)
+ strcpy (subject_str, msg+9);
}
return 1;
}
+#if !USE_MONITOR
static void start_kernel (int argc, char **argv, int id)
{
pid_t pid;
}
if (!pid)
{
- execvp ("kernel", argv_p);
+ execv ("kernel", argv_p);
gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, module, "execvp");
exit (1);
}
}
+#endif
+
+static void deliver (struct str_queue *sq, GIP gip, const char *msg)
+{
+ int index = 0;
+
+ gip_wline (gip, msg);
+ while ((msg = str_queue_get (sq, index++)))
+ gip_wline (gip, msg);
+ gip_wline (gip, "\001");
+}
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;
static int pass = 0;
char fifo_client_name[1024];
char fifo_server_name[1024];
+ struct str_queue *queue;
gw_log_init (*argv);
gw_log_level (GW_LOG_ALL);
gw_log_file (GW_LOG_ALL, "eti.log");
- r = email_header (stdin, from_str, subject_str);
+
+ 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))
+ str_queue_enq (queue, line_str);
+
+ r = email_header (queue, from_str, subject_str);
if (! *from_str)
{
gw_log (GW_LOG_WARN, module, "No \"From\" in mail");
else
{
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
gip = gipc_initialize (fifo_client_name);
signal (SIGPIPE, pipe_handle);
setjmp (retry_jmp);
++pass;
+ signal (SIGPIPE, pipe_handle);
gw_log (GW_LOG_DEBUG, module, "Pass %d", pass);
if (pass == 1)
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
+
+ mknod (fifo_server_name, S_IFIFO|0666, 0);
start_kernel (argc, argv, id);
r = gipc_open (gip, fifo_server_name, 1);
}
{
gw_log (GW_LOG_FATAL, module, "Cannot start kernel");
exit (1);
+#endif
}
if (r < 0)
if (r == -2)
{
- gw_log (GW_LOG_WARN|GW_LOG_ERRNO, module, "r==-2");
+ gw_log (GW_LOG_DEBUG|GW_LOG_ERRNO, module, "r==-2");
longjmp (retry_jmp, 1);
}
else if (r == -1)
{
- gw_log (GW_LOG_WARN|GW_LOG_ERRNO, module, "r==-1");
+ gw_log (GW_LOG_DEBUG|GW_LOG_ERRNO, module, "r==-1");
longjmp (retry_jmp, 1);
}
else
exit (1);
}
/* deliver message ... */
- gw_log (GW_LOG_DEBUG, module, "Delivering mail header");
- gip_wline (gip, "mail\n");
- gip_wline (gip, "From ");
- gip_wline (gip, from_str);
- gip_wline (gip, "\n");
- if (*subject_str)
- {
- gip_wline (gip, "Subject: ");
- gip_wline (gip, subject_str);
- gip_wline (gip, "\n");
- }
- gip_wline (gip, "\n");
- gw_log (GW_LOG_DEBUG, module, "Delivering mail body");
- while (fgets (line_str, LINE_MAX, stdin))
- gip_wline (gip, line_str);
- gip_wline (gip, "\001");
+ gw_log (GW_LOG_DEBUG, module, "Delivering mail");
+#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);
gw_db_close (user_db);
+ gw_log (GW_LOG_DEBUG, module, "Exiting");
exit (0);
}