Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Friday, October 16, 2026

Diff for ep/src/proctable.c between version 1.18 and 1.19

version 1.18, 2002/04/09 21:16:45 version 1.19, 2002/04/10 19:17:51
Line 30 
Line 30 
   
 #include "proctable.h"  #include "proctable.h"
 #include "process.h"  #include "process.h"
 #include "message.h"  #include "message.h" /* msg_*_print() */
 #include "conf.h"  #include "conf.h" /* cfg */
   
   
 static char buf[BUFSIZE];  static char buf[BUFSIZE];
   
   
         int          int
 proctable_get_size(ptbl)  proctable_get_size(ptbl)
         PROCTABLE ptbl;          PROCTABLE ptbl;
Line 442  proctable_remove_process(p_ptbl, proc_id
Line 444  proctable_remove_process(p_ptbl, proc_id
                         p_ptbl, *p_ptbl, proc_id);                          p_ptbl, *p_ptbl, proc_id);
 #endif  #endif
   
           for (k = 0; k < N_FD; k++) {
                   if (proctable_remove_process_fd_links(*p_ptbl, proc_id, k) == -1)
                           return -1;
           }
   
         for (i = 0; (*p_ptbl)[i] != NULL; i++) {          for (i = 0; (*p_ptbl)[i] != NULL; i++) {
                 for (k = 0; k < N_FD; k++) {                  for (k = 0; k < N_FD; k++) {
 #if DEBUG  #if DEBUG
                         msg_debug_print("  process %d fd %d n_link %d\n",                          msg_debug_print("  process %d fd %d n_link %d\n",
                                         i, k, (*p_ptbl)[i]->fd[k].n_link);                                          i, k, (*p_ptbl)[i]->fd[k].n_link);
 #endif  #endif
                         for (j = 0; j < (*p_ptbl)[i]->fd[k].n_link; ) {                          for (j = 0; j < (*p_ptbl)[i]->fd[k].n_link; /* empty */) {
                                 /*msg_debug_print("XXX: %p =? %p\n",  
                                   &(*p_ptbl)[i]->fd[k], &((*p_ptbl)[i]->fd[k]));*/  
   
                                 if ((*p_ptbl)[i]->fd[k].link[j].proc_id == proc_id) {                                  if ((*p_ptbl)[i]->fd[k].link[j].proc_id == proc_id) {
                                         fd_remove_proclink_by_index(&(*p_ptbl)[i]->fd[k], j);                                          /* fd_remove_proclink_by_index(&(*p_ptbl)[i]->fd[k], j); */
                                 }                                  }
                                 else {                                  else {
                                         if ((*p_ptbl)[i]->fd[k].link[j].proc_id > proc_id)                                          if ((*p_ptbl)[i]->fd[k].link[j].proc_id > proc_id)
Line 493  proctable_remove_process(p_ptbl, proc_id
Line 498  proctable_remove_process(p_ptbl, proc_id
         return 0;          return 0;
 }  }
   
           int
   proctable_remove_process_fd_links(ptbl, proc_id, fd_id)
           PROCTABLE ptbl;
           int       proc_id;
           int       fd_id;
   {
           while (ptbl[proc_id]->fd[fd_id].n_link > 0) {
                   register int a_proc_id, a_fd_id;
   
                   /* 0 means the first proclink;
                      we want remove them all */
                   a_proc_id = ptbl[proc_id]->fd[fd_id].link[0].proc_id;
                   a_fd_id   = ptbl[proc_id]->fd[fd_id].link[0].fd_id;
   
                   /* Process 1: id: i,       fd: k     */
                   /* Process 2: id: proc_id, fd: fd_id */
   
                   if (
                                   fd_remove_proclink2(
                                           &((ptbl[a_proc_id])->fd[a_fd_id]),
                                           proc_id, fd_id) == 0
                                   ||
                                   fd_remove_proclink2(
                                           &((ptbl[proc_id])->fd[fd_id]),
                                           a_proc_id, a_fd_id) == 0
                      )
                           return -1;
           }
   
           return 0;
   }
   
         void          void
 proctable_print(ptbl)  proctable_print(ptbl)
Line 577  proctable_read(p_ptbl, p_rfds, p_wfds, p
Line 613  proctable_read(p_ptbl, p_rfds, p_wfds, p
                                 }                                  }
   
                                 if (datasize == 0) {                                  if (datasize == 0) {
                                         /* datasize is 0, we are going to remove all proclinks                                          /* Variable datasize is 0, we are going to remove
                                            from/to this filedescriptor */                                             all proclinks from/to this filedescriptor. */
                                         while ((*p_ptbl)[i]->fd[k].n_link > 0) {  
                                                 register int proc_id, fd_id;                                          proctable_remove_process_fd_links(*p_ptbl, i, k);
   
                                                 /* 0 means the first proclink;  
                                                    we want remove them all */  
                                                 proc_id = (*p_ptbl)[i]->fd[k].link[0].proc_id;  
                                                 fd_id   = (*p_ptbl)[i]->fd[k].link[0].fd_id;  
   
                                                 /* Process 1: id: i,       fd: k     */  
                                                 /* Process 2: id: proc_id, fd: fd_id */  
   
                                                 fd_remove_proclink2(&(((*p_ptbl)[proc_id])->fd[fd_id]),  
                                                                 i, k);  
                                                 fd_remove_proclink2(&(((*p_ptbl)[i])->fd[k]),  
                                                                 proc_id, fd_id);  
                                         }  
                                 }                                  }
                                 else {                                  else {
                                         /* datasize is not null, we are going to transfer                                          /* Variable datasize is not 0, we are going to
                                            datasize bytes to linked filedescriptors */                                             transfer datasize bytes to linked filedescriptors. */
   
                                         for (j = 0; j < (*p_ptbl)[i]->fd[k].n_link; j++) {                                          for (j = 0; j < (*p_ptbl)[i]->fd[k].n_link; j++) {
                                                 register int fd_write;  
                                                 register int proc_id, fd_id;                                                  register int proc_id, fd_id;
                                                   register int fd_write;
   
                                                 proc_id  = (*p_ptbl)[i]->fd[k].link[j].proc_id;                                                  proc_id  = (*p_ptbl)[i]->fd[k].link[j].proc_id;
                                                 fd_id    = (*p_ptbl)[i]->fd[k].link[j].fd_id;                                                  fd_id    = (*p_ptbl)[i]->fd[k].link[j].fd_id;
Line 679  proctable_wait(p_ptbl)
Line 702  proctable_wait(p_ptbl)
 #endif  #endif
   
                         /* We will check if there is a process which should be                          /* We will check if there is a process which should be
                          * terminated. If it is, we will return 1 and than main                             terminated. If it is, we will return 1 and than main
                          * program will call us again after select() timeout.                             program will call us again after select() timeout. */
                          */  
                         {                          {
                                 register int i, k, proc_n_link = 1;                                  register int i, k, proc_n_link = 1;
   
Line 695  proctable_wait(p_ptbl)
Line 717  proctable_wait(p_ptbl)
                                                 msg_debug_print("proctable_wait(): candidate index = %d\n", i);                                                  msg_debug_print("proctable_wait(): candidate index = %d\n", i);
 #endif  #endif
                                                 /* Don't need to browse the process table more. */                                                  /* Don't need to browse the process table more. */
                                                   /* THIS IS WRONG! */
                                                 break;                                                  break;
                                         }                                          }
                                 }                                  }
Line 771  proctable_wait(p_ptbl)
Line 794  proctable_wait(p_ptbl)
         return pid;          return pid;
 }  }
   
           int
   proctable_wait2(p_ptbl)
           PROCTABLE *p_ptbl;
   {
           register int i, k, proc_n_link = 1;
           int pid = 0;
           int status;
   
           for (i = 1; (*p_ptbl)[i] != NULL; i++) {
   
                   for (proc_n_link = 0, k = 0; k < N_FD; k++)
                           proc_n_link += (*p_ptbl)[i]->fd[k].n_link;
   
                   if (proc_n_link == 0) {
   #if DEBUG
                           msg_debug_print("proctable_wait2(): candidate index = %d\n", i);
   #endif
                           pid = waitpid((*p_ptbl)[i]->pid, &status, WNOHANG);
   
                           switch (pid) {
                                   case -1:
   #if 0
                                           msg_error_print("proctable_wait2(): "
                                                           "waitpid() failure: %s\n", strerror(errno));
   #endif
   
                                           return pid;
                                           break;
   
                                   case 0:
   #if DEBUG
                                           msg_warn_print("proctable_wait2(): "
                                                           "waitpid() warning: no child available\n");
   #endif
                                           break;
                                   default:
                                           if (! cfg.silent) {
                                                   msg_print("[%d] ", pid);
   
                                                   if (WIFEXITED(status)) {
                                                           msg_print("Exit");
                                                           if (WEXITSTATUS(status))
                                                                   msg_print(" %d", WEXITSTATUS(status));
                                                   }
                                                   else if (WIFSIGNALED(status)) {
                                                           register int sig_n = WTERMSIG(status);
   
                                                           switch (sig_n) {
                                                                   case SIGKILL:
                                                                           msg_print("Killed");
                                                                           break;
                                                                   case SIGTERM:
                                                                           msg_print("Terminated");
                                                                           break;
                                                                   case SIGSEGV:
                                                                           msg_print("Segmentation fault");
                                                                           break;
                                                                   default:
                                                                           msg_print("Received signal %d", sig_n);
                                                                           break;
                                                           };
                                                   }
                                                   else {
                                                           msg_print("Aborted", pid);
                                                   }
   
                                                   msg_print("\t\t\t\t");
                                                   msg_array_print((*p_ptbl)[i]->argv);
                                                   msg_print("\n");
                                           } /* if (! cfg.silent) */
   
                                           proctable_remove_process(p_ptbl, i);
                                           return pid;
   
                                           break;
                           }
                   }
           }
   
           return 0;
   }

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.19

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top