* Europagate, 1995
*
* $Log: monitor.c,v $
- * Revision 1.2 1995/05/01 16:26:57 adam
+ * Revision 1.3 1995/05/02 07:20:10 adam
+ * Use pid of exited child to close fifos.
+ *
+ * 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
static jmp_buf retry_jmp;
struct ke_info {
- int pid;
+ pid_t pid;
int id;
GIP gip;
struct str_queue *queue;
static void catchchild (int num)
{
- while (waitpid (-1, 0, WNOHANG) > 0)
- ;
+ pid_t pid;
+ struct ke_info *ki;
+
+ while ((pid=waitpid (-1, 0, WNOHANG)) > 0)
+ for (ki = ke_info_list; ki; ki = ki->next)
+ if (ki->pid == pid)
+ {
+ gw_log (GW_LOG_DEBUG, module, "Close of %d", ki->id);
+ if (ki->gip)
+ {
+ gipc_close (ki->gip);
+ gipc_destroy (ki->gip);
+ ki->gip = NULL;
+ }
+ }
signal (SIGCHLD, catchchild);
}
}
static void deliver (int argc, char **argv, int id, struct str_queue *queue,
- GIP *gip)
+ GIP *gip, pid_t *pidp)
{
int pass = 0;
int r;
r = gipc_open (*gip, fifo_server_name, 0);
else if (pass == 2)
{
+ pid_t pid;
+
mknod (fifo_server_name, S_IFIFO|0666, 0);
- start_kernel (argc, argv, id);
+ pid = start_kernel (argc, argv, id);
+ if (pidp)
+ *pidp = pid;
r = gipc_open (*gip, fifo_server_name, 1);
}
else
int fd_max;
struct ke_info *ki;
- FD_ZERO (&set_r);
- 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);
- deliver (argc, argv, ki->id, ki->queue, &ki->gip);
- str_queue_rm (&ki->queue);
- }
- for (ki = ke_info_list; ki; ki = ki->next)
+ while (1)
{
- int fd;
- if (ki->gip && (fd = gip_infileno (ki->gip)) != -1)
+ FD_ZERO (&set_r);
+ 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)
{
- gw_log (GW_LOG_DEBUG, module, "set r %d", fd);
- FD_SET (fd, &set_r);
- if (fd > fd_max)
- fd_max = fd;
+ if (!ki->queue)
+ continue;
+ gw_log (GW_LOG_DEBUG, module, "Transfer mail to %d", ki->id);
+ deliver (argc, argv, ki->id, ki->queue, &ki->gip, &ki->pid);
+ str_queue_rm (&ki->queue);
+ }
+ 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);
+ FD_SET (fd, &set_r);
+ if (fd > fd_max)
+ fd_max = fd;
+ }
}
- }
- while (1)
- {
gw_log (GW_LOG_DEBUG, module, "IPC select");
r = select (fd_max+1, &set_r, NULL, NULL, NULL);
if (r != -1)
{
gw_log_init (*argv);
gw_log_level (GW_LOG_ALL);
-#if 0
signal (SIGCHLD, catchchild);
+#if 0
gw_log_file (GW_LOG_ALL, "monitor.log");
#endif
monitor_events (argc, argv);