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.10 and 1.11

version 1.10, 2002/02/05 22:37:03 version 1.11, 2002/02/06 21:44:11
Line 303  proctable_update(ptbl)
Line 303  proctable_update(ptbl)
                                                                         break;                                                                          break;
   
                                         }                                          }
   
                                         msg_error_print(                                          msg_error_print(
                                                         "incorrect link -- [%d].%s -> [%d].%s\n",                                                          "incorrect link -- [%d].%s -> [%d].%s\n",
                                                         i, fd_str[0][k],                                                          i, fd_str[0][k],
                                                         ptbl[i]->fd[k].link[j].proc_id,                                                          ptbl[i]->fd[k].link[j].proc_id,
                                                         fd_str[0][ptbl[i]->fd[k].link[j].fd_id]);                                                          fd_str[0][ptbl[i]->fd[k].link[j].fd_id]);
   
                                         return -1;                                          return -1;
                                 }                                  }
   
Line 388  proctable_exec(ptbl)
Line 390  proctable_exec(ptbl)
                                 for (k = 0; k < N_FD; k++)                                  for (k = 0; k < N_FD; k++)
                                         /* XXX: We want to dup pipe anyway. */                                          /* XXX: We want to dup pipe anyway. */
                                         if (1 || ptbl[i]->fd[k].n_link != 0) {                                          if (1 || ptbl[i]->fd[k].n_link != 0) {
 #if 0  
                                                 close(k);  
                                                 dup(ptbl[i]->fd[k].pipe[k ? 1 : 0]);  
 #else  
                                                 dup2(ptbl[i]->fd[k].pipe[k ? 1 : 0], k);                                                  dup2(ptbl[i]->fd[k].pipe[k ? 1 : 0], k);
   
 #endif  
                                                 /* See the '1 ||' below.                                                  /* See the '1 ||' below.
                                                    close(ptbl[i]->fd[k].pipe[0]);                                                     close(ptbl[i]->fd[k].pipe[0]);
                                                    close(ptbl[i]->fd[k].pipe[1]);                                                     close(ptbl[i]->fd[k].pipe[1]);
Line 414  proctable_exec(ptbl)
Line 412  proctable_exec(ptbl)
                                                         close(ptbl[j]->fd[k].pipe[1]);                                                          close(ptbl[j]->fd[k].pipe[1]);
                                                 }                                                  }
                                 }                                  }
                                 /*  #if 0
                                    for (k = 0; k < N_FD; k++)  
                                    if (ptbl[i]->fd[k].n_link == 0)  
                                    close(k);  
                                    */  
                                 /* setvbuf(stdout, NULL, _IONBF, 0); */                                  /* setvbuf(stdout, NULL, _IONBF, 0); */
                                 /* setbuf(stdout, NULL); */                                  /* setbuf(stdout, NULL); */
   
                                 /*  
                                    for (k = 0; k < N_FD; k++) {  
                                    if (k != 0) {  
                                    fcntl(k, F_SETFL, O_NONBLOCK|O_NDELAY);  
                                    msg_print("Running fcntl()\n");  
                                    }  
                                    }  
                                    */  
   
                                 for (k = 0; k < N_FD; k++) {                                  for (k = 0; k < N_FD; k++) {
                                         if (k > 0) {                                          if (k > 0) {
                                                 fchmod(k, 030620);                                                  fchmod(k, 030620);
                                                 fcntl(k, F_SETFL, O_NONBLOCK|O_NDELAY);                                                  fcntl(k, F_SETFL, O_NONBLOCK|O_NDELAY);
                                         }                                          }
                                 }                                  }
   #endif
   
                                 execvp(ptbl[i]->argv[0], ptbl[i]->argv);                                  execvp(ptbl[i]->argv[0], ptbl[i]->argv);
                                 //execve(ptbl[i]->argv[0], ptbl[i]->argv, environ);                                  /* execve(ptbl[i]->argv[0], ptbl[i]->argv, environ); */
   
                                 /*                                  /*
                                  * RETURN VALUES                                   * RETURN VALUES
Line 477  proctable_remove_process(p_ptbl, index)
Line 463  proctable_remove_process(p_ptbl, index)
 {  {
         register int i, j, k;          register int i, j, k;
   
 #if 0  
         register int proctable_size;  
   
         /*          /*
          * We need to save value of process table size.           * Pri odstraneni procesu je nutne:
            * - odstranit process z tabulky PROCTABLE a posunut vsetky za nim
            * - prepisat vsetky linky v PROCTABLE
            * - zrusit vsetky linky odkazujuce na dany process
            *
            * Nepto [3/4/2001]
          */           */
         proctable_size = proctable_get_size(*p_ptbl);  
 #endif  
   
         /////////////////////////////////////////////////////////////////////  #if DEBUG
         // Pri odstraneni procesu je nutne:          msg_debug_print("proctable_remove_process(%p [%p], %d)\n",
         // - odstranit process z tabulky PROCTABLE a posunut vsetky za nim                          p_ptbl, *p_ptbl, index);
         // - prepisat vsetky linky v PROCTABLE  #endif
         // - zrusit vsetky linky odkazujuce na dany process  
         //  
         // Nepto [3/4/2001]  
   
         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
                           msg_debug_print("  process %d fd %d n_link %d\n",
                                           i, k, (*p_ptbl)[i]->fd[k].n_link);
   #endif
                         for (j = 0; j < (*p_ptbl)[i]->fd[k].n_link; j++) {                          for (j = 0; j < (*p_ptbl)[i]->fd[k].n_link; j++) {
                                   /*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 > index)                                  if ((*p_ptbl)[i]->fd[k].link[j].proc_id > index)
                                         (*p_ptbl)[i]->fd[k].link[j].proc_id--;                                          (*p_ptbl)[i]->fd[k].link[j].proc_id--;
                                 else                                  else
                                         if ((*p_ptbl)[i]->fd[k].link[j].proc_id == index)                                          if ((*p_ptbl)[i]->fd[k].link[j].proc_id == index) {
                                                 fd_remove_proclink_by_index(&(*p_ptbl)[i]->fd[k], j);                                                  fd_remove_proclink_by_index(&(*p_ptbl)[i]->fd[k], j);
   
                                           }
                         }                          }
                 }                  }
         }          }
   
   
         // tu som sepalil cely process  
   
         process_destroy((*p_ptbl)[index]);          process_destroy((*p_ptbl)[index]);
   
         for (i = index; (*p_ptbl)[i] != NULL; i++) {          for (i = index; (*p_ptbl)[i] != NULL; i++) {
Line 518  proctable_remove_process(p_ptbl, index)
Line 507  proctable_remove_process(p_ptbl, index)
         /* Process table is a list of process ended with NULL.        */          /* Process table is a list of process ended with NULL.        */
         /* Resizing process table: '-1' is for size down by 1         */          /* Resizing process table: '-1' is for size down by 1         */
         /*                         '+1' cause we already go down by 1 */          /*                         '+1' cause we already go down by 1 */
         /*                              see the for () above           */          /*                              see the for () above          */
         /*                         '+1' is for ending NULL            */          /*                         '+1' is for ending NULL            */
         /* So the final is '+1'.                                      */          /* So the final is '+1'.                                      */
   
         *p_ptbl = (PROCTABLE) realloc(*p_ptbl,          *p_ptbl = (PROCTABLE) realloc(*p_ptbl,
                         (proctable_get_size(*p_ptbl) + 1)                          (proctable_get_size(*p_ptbl) + 1) * sizeof(struct process *));
                         * sizeof(struct process *));  
   
         if (*p_ptbl == NULL) {          if (*p_ptbl == NULL) {
                 msg_error_print("proctable_remove_process(): realloc() failure\n");                  msg_error_print("proctable_remove_process(): realloc() failure\n");
                 return -1;                  return -1;
         }          }
   
   #if DEBUG
           msg_debug_print("proctable_remove_process(%p [%p])\n",
                           p_ptbl, *p_ptbl);
   #endif
   
         return 0;          return 0;
 }  }
   
Line 563  proctable_print(ptbl)
Line 556  proctable_print(ptbl)
   
   
         int          int
 proctable_read(p_ptbl, p_fds)  proctable_read_old(p_ptbl, p_fds)
         PROCTABLE *p_ptbl;          PROCTABLE *p_ptbl;
         fd_set *p_fds;          fd_set *p_fds;
 {  {
Line 626  proctable_read(p_ptbl, p_fds)
Line 619  proctable_read(p_ptbl, p_fds)
                                                                 &(((*p_ptbl)[p1.proc_id])->fd[p1.fd_id]), &p2);                                                                  &(((*p_ptbl)[p1.proc_id])->fd[p1.fd_id]), &p2);
   
                                                 if (((*p_ptbl)[p2.proc_id])->fd[p2.fd_id].n_link == 0)                                                  if (((*p_ptbl)[p2.proc_id])->fd[p2.fd_id].n_link == 0)
                                                         close(((*p_ptbl)[p2.proc_id])->                                                          /*my_*/close(((*p_ptbl)[p2.proc_id])->
                                                                         fd[p2.fd_id].pipe[1]);                                                                          fd[p2.fd_id].pipe[1]);
   
                                                 if (((*p_ptbl)[p2.proc_id])->fd[p2.fd_id].n_link == 0)                                                  if (((*p_ptbl)[p2.proc_id])->fd[p2.fd_id].n_link == 0)
                                                         close(((*p_ptbl)[p2.proc_id])->                                                          /*my_*/close(((*p_ptbl)[p2.proc_id])->
                                                                         fd[p2.fd_id].pipe[1]);                                                                          fd[p2.fd_id].pipe[1]);
   
                                         }                                          }
Line 675  proctable_read(p_ptbl, p_fds)
Line 668  proctable_read(p_ptbl, p_fds)
         return 0;          return 0;
 }  }
   
           int
   proctable_read(p_ptbl, p_rfds, p_efds)
           PROCTABLE *p_ptbl;
           fd_set *p_rfds;
           fd_set *p_efds;
   {
           register int i, k, datasize = 1;
           char buf[BUFSIZE];
   
           for (i = 0; (*p_ptbl)[i] != NULL; i++) {
                   for (k = 0; k < N_FD; k++) {
                           if (FD_ISSET((*p_ptbl)[i]->fd[k].pipe[0], p_efds)) {
                                   FD_CLR((*p_ptbl)[i]->fd[k].pipe[0], p_efds);
   #if DEBUG
                                   msg_debug_print("proctable_read(): exception:"
                                                   " process %d, fd %d, real fd %d\n",
                                                   i, k, (*p_ptbl)[i]->fd[k].pipe[0]);
   #endif
                           }
                   }
   
                   for (k = (i ? 1 : 0); k < (i ? N_FD : 1); k++) {
                           if (FD_ISSET((*p_ptbl)[i]->fd[k].pipe[0], p_rfds)) {
                                   register int j;
   
                                   FD_CLR((*p_ptbl)[i]->fd[k].pipe[0], p_rfds);
   
                                   datasize = read((*p_ptbl)[i]->fd[k].pipe[0],
                                                   buf, BUFSIZE);
   
   #if 0 && DEBUG
                                   msg_debug_print("proctable_read(): descriptor change:"
                                                   " process %d, fd %d, datasize %d\n",
                                                   i, k, datasize);
   #endif
   
                                   if (datasize == 0) {
                                           close((*p_ptbl)[i]->fd[k].pipe[0]);
   #if DEBUG
                                           msg_debug_print("proctable_read(): close(%d)\n",
                                                           (*p_ptbl)[i]->fd[k].pipe[0]);
   #endif
                                   }
   
                                   if (datasize < 0) {
   #if DEBUG
                                           msg_debug_print("proctable_read(): "
                                                           "read() failure, %d returned\n",
                                                           datasize);
   #endif
                                           msg_errno_print();
                                           msg_print("Terminating...");
                                           exit(1);
                                   }
   
                                   for (j = 0; j < (*p_ptbl)[i]->fd[k].n_link; j++) {
                                           register int proc_id, fd_id;
                                           register int fd_write;
   
                                           proc_id = (*p_ptbl)[i]->fd[k].link[j].proc_id;
                                           fd_id = (*p_ptbl)[i]->fd[k].link[j].fd_id;
   
                                           fd_write = (*p_ptbl)[proc_id]->fd[fd_id].pipe[1];
   
                                           if (datasize == 0) {
                                                   /* 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);
   #if 0
                                                   if (((*p_ptbl)[proc_id])->fd[fd_id].n_link == 0) {
                                                           my_close(fd_write);
                                                           /* FIXME: not needed probably */
                                                           my_close((*p_ptbl)[proc_id]->fd[fd_id].pipe[0]);
                                                   }
   #endif
                                           }
                                           else {
   #if 0 && DEBUG
                                                   msg_debug_print("proctable_read(): descriptor write:"
                                                                   " process %d, fd %d, datasize %d\n",
                                                                   proc_idx, fd_write, datasize);
   #endif
   
                                                   switch (write(fd_write, buf, datasize)) {
                                                           case -1:
   #if DEBUG
                                                                   msg_debug_print("proctable_read(): "
                                                                                   "write() failed: %s\n",
                                                                                   strerror(errno));
   #endif
                                                                   break;
                                                           case 0:
   #if DEBUG
                                                                   msg_debug_print("proctable_read(): "
                                                                                   "write() returns 0: %s\n",
                                                                                   strerror(errno));
   #endif
                                                                   break;
                                                           default:
                                                                   break;
                                                   }
                                           }
                                   }
                           } /* if (FD_ISSET()) */
                           else
                                   datasize = 1;
   
                           if (! datasize)
                                   break;
                   }
                   if (! datasize)
                           break;
           }
   
           //msg_debug_print("datasize on exit %d\n", datasize);
   
           /* Returns 0 if process was removed, 1 elsewhere. */
           return datasize;
   }
   
         int          int
 proctable_wait(p_ptbl)  proctable_wait(p_ptbl)
Line 683  proctable_wait(p_ptbl)
Line 799  proctable_wait(p_ptbl)
         register int i, k, proc_n_link, f_wait_call = 0;          register int i, k, proc_n_link, f_wait_call = 0;
         int pid = 0;          int pid = 0;
   
   #if 0
         for (i = 0; (*p_ptbl)[i] != NULL; i++) {          for (i = 0; (*p_ptbl)[i] != NULL; i++) {
                 if (! i)                  if (! i)
                         continue;                          continue;
Line 696  proctable_wait(p_ptbl)
Line 813  proctable_wait(p_ptbl)
                         /* Set up the wait() call. */                          /* Set up the wait() call. */
                         f_wait_call = 1;                          f_wait_call = 1;
   
   #if DEBUG
                           msg_debug_print("proctable_wait(): candidate index = %d\n", i);
   #endif
   
                         /* Don't need to browse the process table more. */                          /* Don't need to browse the process table more. */
                         break;                          break;
                 }                  }
         }          }
   #endif
   
         if (f_wait_call != 0) {          if (1 || f_wait_call != 0) {
                 int status;                  int status;
   
 #if DEBUG  #if DEBUG
                 msg_debug_print("proctable_wait(): f_wait_call == 1, calling wait()\n");                  msg_debug_print("proctable_wait(): f_wait_call == 1, calling wait()\n");
 #endif  #endif
                   /*
                 // Parameters in waitpid:                   * Parameters in waitpid:
                 // -1 == wait for any child process                   * -1 == wait for any child process
                 // WNOHANG == return immediately if no child has exited.                   * WNOHANG == return immediately if no child has exited.
                    */
                 pid = waitpid(-1, &status, WNOHANG);                  pid = waitpid(-1, &status, WNOHANG);
   
                 switch (pid) {                  switch (pid) {
Line 722  proctable_wait(p_ptbl)
Line 845  proctable_wait(p_ptbl)
                                 break;                                  break;
   
                         case 0:                          case 0:
   #if DEBUG
                                 msg_warn_print("proctable_wait(): "                                  msg_warn_print("proctable_wait(): "
                                                 "waitpid() warning: no child available\n");                                                  "waitpid() warning: no child available\n");
   #endif
   
                                   pid = 1;
                                 break;                                  break;
   
                         default:                          default:
Line 733  proctable_wait(p_ptbl)
Line 860  proctable_wait(p_ptbl)
                                         index = proctable_get_process_index_by_pid(*p_ptbl, pid);                                          index = proctable_get_process_index_by_pid(*p_ptbl, pid);
 #if DEBUG  #if DEBUG
                                         msg_debug_print("proctable_wait(): "                                          msg_debug_print("proctable_wait(): "
                                                         "PID = %d, index = %d\n",                                                          "pid = %d, index = %d\n",
                                                         index, pid);                                                          pid, index);
   
                                         msg_debug_print("proctable_wait(): "                                          msg_debug_print("proctable_wait(): "
                                                         "proctable_get_size() = %d\n",                                                          "proctable_get_size() = %d\n",
                                                         proctable_get_size(*p_ptbl));                                                          proctable_get_size(*p_ptbl));
 #endif  #endif
                                         if (WIFEXITED(status))                                          msg_print("[%d] ", pid);
                                                 if (!WEXITSTATUS(status)) {  
                                                         msg_print("[%d] - exit - ", pid);  
                                                         msg_array_print((*p_ptbl)[index]->argv);  
                                                         msg_print("\n");  
                                                 }  
                                                 else {  
                                                         msg_print("[%d] - error %d: %s - ",  
                                                                         pid,  
                                                                         WEXITSTATUS(status),  
                                                                         strerror(  
                                                                                 WEXITSTATUS(status)));  
                                                         msg_array_print((*p_ptbl)[index]->argv);  
                                                         msg_print("\n");  
                                                 }  
   
                                         if (WIFSIGNALED(status)) {                                          if (WIFEXITED(status)) {
                                                 msg_print("[%d] - killed by signal %d - ",                                                  msg_print("Exit");
                                                                 pid,                                                  if (WEXITSTATUS(status))
                                                                 WTERMSIG(status) );                                                          msg_print(" %d", WEXITSTATUS(status));
                                                 msg_array_print((*p_ptbl)[index]->argv);                                          }
                                                 msg_print("\n");                                          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)[index]->argv);
                                           msg_print("\n");
 #if DEBUG  #if DEBUG
                                         msg_debug_print("proctable_wait(): "                                          msg_debug_print("proctable_wait(): "
                                                         "removing process from process table\n");                                                          "removing process from process table\n");
Line 774  proctable_wait(p_ptbl)
Line 910  proctable_wait(p_ptbl)
                                                         proctable_get_size(*p_ptbl));                                                          proctable_get_size(*p_ptbl));
 #endif  #endif
                                 }                                  }
   
                                 break;                                  break;
                 } /* switch (pid) */                  } /* switch (pid) */
         }          }
           else {
   #if 0 && DEBUG
   
                   pid = waitpid(-1, NULL, WNOHANG);
   
                   switch (pid) {
                           case -1:
                                   msg_debug_print("proctable_wait(): no candicate, "
                                                   "but error occured\n");
                                   pid = 0;
                                   break;
                           case 0:
                                   msg_debug_print("proctable_wait(): no candicate\n");
                                   break;
                           default:
                                   msg_debug_print("proctable_wait(): no candicate, "
                                                   "but process with id %d removed\n", pid);
                                   break;
                   };
   #endif
           }
   
         return pid;          return pid;
 }  }

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

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