From: Adam Dickmeiss Date: Tue, 2 May 1995 07:20:10 +0000 (+0000) Subject: Use pid of exited child to close fifos. X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=e7fd8016cc21ff4442a69c9dfc28b92ff8b3787f;p=egate.git Use pid of exited child to close fifos. --- diff --git a/kernel/monitor.c b/kernel/monitor.c index 43c9aec..9f5f79a 100644 --- a/kernel/monitor.c +++ b/kernel/monitor.c @@ -2,7 +2,10 @@ * 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 @@ -38,7 +41,7 @@ static char *module = "monitor"; static jmp_buf retry_jmp; struct ke_info { - int pid; + pid_t pid; int id; GIP gip; struct str_queue *queue; @@ -80,8 +83,21 @@ void ke_info_del (void) 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); } @@ -127,7 +143,7 @@ static pid_t start_kernel (int argc, char **argv, int id) } 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; @@ -151,8 +167,12 @@ static void deliver (int argc, char **argv, int id, struct str_queue *queue, 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 @@ -204,32 +224,32 @@ static void monitor_events (int argc, char **argv) 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) @@ -298,8 +318,8 @@ int main (int argc, char **argv) { 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);