+ if (got_term)
+ {
+ gw_log (GW_LOG_STAT, module, "Got SIGTERM. Exiting...");
+ unlink (MONITOR_FIFO_S);
+ unlink (MONITOR_FIFO_C);
+ exit (0);
+ }
+ if (got_int)
+ {
+ gw_log (GW_LOG_STAT, module, "Got SIGINT. Exiting...");
+ unlink (MONITOR_FIFO_S);
+ unlink (MONITOR_FIFO_C);
+ exit (0);
+ }
+ /* deliver any unsent messages to Email kernels */
+ too_many = 0;
+ for (ki = ke_info_list; ki; ki = ki->next)
+ {
+ if (!ki->queue || ki->stopped)
+ continue;
+ gw_log (GW_LOG_DEBUG, module, "Transfer mail to %d", ki->id);
+ r = deliver (argc, argv, ki->id, ki->queue, &ki->gip, &ki->pid,
+ no_process >= max_process);
+ if (r == 2) /* new child was spawned? */
+ {
+ ++no_process;
+ gw_log (GW_LOG_DEBUG, module, "Start of %d", ki->id);
+ }
+ if (r == 1 || r == 2) /* transfer at all? */
+ str_queue_rm (&ki->queue);
+ if (r == 0) /* too many pending? */
+ too_many++;
+ }
+ if (too_many)
+ {
+ gw_log (GW_LOG_DEBUG, module, "%d too many pending",
+ too_many);
+ for (ki = ke_info_list; ki; ki = ki->next)
+ {
+ if (!ki->queue && ki->pid != -1 && !ki->stopped)
+ {
+ if (!(ki->queue = str_queue_mk ()))
+ {
+ gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, module,
+ "str_queue_mk");
+ exit (1);
+ }
+ str_queue_enq (ki->queue, "stop\n");
+ str_queue_enq (ki->queue, "\001");
+ r = deliver (argc, argv, ki->id, ki->queue, &ki->gip,
+ &ki->pid, 1);
+ if (r != 1)
+ gw_log (GW_LOG_DEBUG, module,
+ "Stop not sent: %d", r);
+ str_queue_rm (&ki->queue);
+ ki->stopped = 1;
+ break;
+ }
+ }
+ }
+ FD_ZERO (&set_r);
+ FD_SET (gip_m_fd, &set_r);
+ gw_log (GW_LOG_DEBUG, module, "set gip_m_fd %d", gip_m_fd);
+ fd_max = gip_m_fd;
+
+ for (ki = ke_info_list; ki; ki = ki->next)
+ {
+ int fd;
+ if (ki->gip)
+ {
+ if (ki->pid == -1)
+ { /* child has exited */
+ gw_log (GW_LOG_DEBUG, module, "Close of %d", ki->id);
+ gipc_close (ki->gip);
+ gipc_destroy (ki->gip);
+ ki->gip = NULL;
+ ki->stopped = 0;
+ }
+ else if ((fd = gip_infileno (ki->gip)) != -1)
+ { /* read select on child FIFO */
+ gw_log (GW_LOG_DEBUG, module, "set fd %d", fd);
+ FD_SET (fd, &set_r);
+ if (fd > fd_max)
+ fd_max = fd;
+ }
+ }
+ }
+ gw_log (GW_LOG_DEBUG, module, "Cur/Max processes %d/%d",
+ no_process, max_process);