* Europagate, 1995
*
* $Log: main.c,v $
- * Revision 1.20 1995/05/01 12:43:32 adam
+ * Revision 1.21 1995/05/01 16:26:56 adam
+ * More work on resource monitor.
+ *
+ * Revision 1.20 1995/05/01 12:43:32 adam
* First work on resource monitor program.
*
* Revision 1.19 1995/04/19 16:01:58 adam
struct timeval tv;
int timeout;
int continuation = 0;
+ int extra_fd;
timeout = atoi(gw_res_get (info.kernel_res, "gw.timeout", "600"));
- gw_log (GW_LOG_DEBUG, KERNEL_LOG, "kernel event loop");
+ gw_log (GW_LOG_DEBUG, KERNEL_LOG, "event loop");
sprintf (fifo_client_name, "fifo.c.%d", userid);
sprintf (fifo_server_name, "fifo.s.%d", userid);
gip = gips_initialize (fifo_server_name);
gips_open (gip, fifo_client_name);
gip_fd = gip_infileno (gip);
- open (fifo_server_name, O_WRONLY);
+ extra_fd = open (fifo_server_name, O_WRONLY);
while (1)
{
continuation = 1;
}
}
+ close (extra_fd);
gips_close (gip);
gips_destroy (gip);
unlink (fifo_client_name);
* Europagate, 1995
*
* $Log: monitor.c,v $
- * Revision 1.1 1995/05/01 12:43:36 adam
+ * Revision 1.2 1995/05/01 16:26:57 adam
+ * More work on resource monitor.
+ *
+ * Revision 1.1 1995/05/01 12:43:36 adam
* First work on resource monitor program.
*
*/
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
+#include <sys/wait.h>
#include <gw-log.h>
#include <gw-log.h>
free (ki);
}
+static void catchchild (int num)
+{
+ while (waitpid (-1, 0, WNOHANG) > 0)
+ ;
+ signal (SIGCHLD, catchchild);
+}
+
static void pipe_handle (int dummy)
{
longjmp (retry_jmp, 1);
struct ke_info *ki;
FD_ZERO (&set_r);
- FD_SET (gip_m_fd, &set_r);
- fd_max = gip_m_fd;
-
- for (ki = ke_info_list; ki; ki = ki->next)
- {
- if (!ki->queue)
+ FD_SET (gip_m_fd, &set_r);
+ gw_log (GW_LOG_DEBUG, module, "set r %d", gip_m_fd);
+ fd_max = gip_m_fd;
+
+ for (ki = ke_info_list; ki; ki = ki->next)
+ {
+ if (!ki->queue)
continue;
- gw_log (GW_LOG_DEBUG, module, "Transfer mail to %d", ki->id);
+ gw_log (GW_LOG_DEBUG, module, "Transfer mail to %d", ki->id);
deliver (argc, argv, ki->id, ki->queue, &ki->gip);
- str_queue_rm (&ki->queue);
+ str_queue_rm (&ki->queue);
}
- for (ki = ke_info_list; ki; ki = ki->next)
- {
- int fd;
+ for (ki = ke_info_list; ki; ki = ki->next)
+ {
+ int fd;
if (ki->gip && (fd = gip_infileno (ki->gip)) != -1)
- {
- gw_log (GW_LOG_DEBUG, module, "set r %d", fd);
+ {
+ gw_log (GW_LOG_DEBUG, module, "set r %d", fd);
FD_SET (fd, &set_r);
if (fd > fd_max)
fd_max = fd;
- }
- }
- gw_log (GW_LOG_DEBUG, module, "Monitor select");
- r = select (fd_max+1, &set_r, NULL, NULL, NULL);
- if (r == -1)
+ }
+ }
+ while (1)
+ {
+ gw_log (GW_LOG_DEBUG, module, "IPC select");
+ r = select (fd_max+1, &set_r, NULL, NULL, NULL);
+ if (r != -1)
+ break;
+ if (errno != EINTR)
+ {
+ gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, module, "select");
+ exit (1);
+ }
+ gw_log (GW_LOG_DEBUG|GW_LOG_ERRNO, module, "select");
+ }
+ gw_log (GW_LOG_DEBUG, module, "Testing ke_info_list");
+ for (ki = ke_info_list; ki; ki = ki->next)
{
- gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, module, "select");
- exit (1);
+ int fd;
+ if (ki->gip && (fd = gip_infileno (ki->gip)) != -1)
+ {
+ gw_log (GW_LOG_DEBUG, module, "Test of %d", fd);
+ if (FD_ISSET (fd, &set_r))
+ {
+ if (lgets (line_buf, sizeof(line_buf)-1, fd))
+ {
+ gw_log (GW_LOG_DEBUG, module, "IPC: %s", line_buf);
+ }
+ else
+ {
+ gw_log (GW_LOG_DEBUG, module, "Close of %d", ki->id);
+ gipc_close (ki->gip);
+ gipc_destroy (ki->gip);
+ ki->gip = NULL;
+ }
+ }
+ }
}
+
+ gw_log (GW_LOG_DEBUG, module, "Testing gip_m_fd %d", gip_m_fd);
if (FD_ISSET (gip_m_fd, &set_r))
{
+ gw_log (GW_LOG_DEBUG, module, "Reading from %d", gip_m_fd);
if (!(lgets (command, sizeof(command)-1, gip_m_fd)))
{
gw_log (GW_LOG_FATAL, module, "Unexpected close");
exit (1);
}
+ gw_log (GW_LOG_DEBUG, module, "Done");
if ((cp = strchr (command, '\n')))
*cp = '\0';
gw_log (GW_LOG_DEBUG, module, "IPC: %s", command);
{
int id = atoi (command+4);
struct ke_info *new_k;
-
+
new_k = ke_info_add (id);
- gw_log (GW_LOG_DEBUG, "module", "Incoming mail %d", id);
+ gw_log (GW_LOG_DEBUG, module, "Incoming mail %d", id);
str_queue_enq (new_k->queue, "mail\n");
while (lgets (line_buf, sizeof(line_buf)-1, gip_m_fd))
str_queue_enq (new_k->queue, line_buf);
str_queue_enq (new_k->queue, "\001");
}
}
- for (ki = ke_info_list; ki; ki = ki->next)
- {
- int fd;
- if (ki->gip && (fd = gip_infileno (ki->gip)) != -1 &&
- FD_ISSET (fd, &set_r))
- {
- if (lgets (line_buf, sizeof(line_buf)-1, fd))
- {
- gw_log (GW_LOG_DEBUG, module, "IPC: %s", line_buf);
- }
- else
- {
- gw_log (GW_LOG_DEBUG, module, "Close of %d", ki->id);
- gipc_close (ki->gip);
- gipc_destroy (ki->gip);
- ki->gip = NULL;
- }
- }
- }
}
}
{
gw_log_init (*argv);
gw_log_level (GW_LOG_ALL);
+#if 0
+ signal (SIGCHLD, catchchild);
gw_log_file (GW_LOG_ALL, "monitor.log");
-
+#endif
monitor_events (argc, argv);
exit (0);
}
+
+
+