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.4 and 1.5

version 1.4, 2001/12/02 23:30:07 version 1.5, 2001/12/04 17:17:52
Line 1 
Line 1 
 /*  /*
  * $Log$   * $Log$
    * Revision 1.5  2001/12/04 17:17:52  jombik9
    * n_link sychronizations
    *
  * Revision 1.4  2001/12/02 23:30:07  jombik9   * Revision 1.4  2001/12/02 23:30:07  jombik9
  * A lot of new functions added.   * A lot of new functions added.
  * Various improvements.   * Various improvements.
Line 9 
Line 12 
  *   *
  * Revision 1.2  2001/09/21 19:44:51  host8   * Revision 1.2  2001/09/21 19:44:51  host8
  * Added $Log$   * Added $Log$
    * Added Revision 1.5  2001/12/04 17:17:52  jombik9
    * Added n_link sychronizations
    * Added
  * Added Revision 1.4  2001/12/02 23:30:07  jombik9   * Added Revision 1.4  2001/12/02 23:30:07  jombik9
  * Added A lot of new functions added.   * Added A lot of new functions added.
  * Added Various improvements.   * Added Various improvements.
Line 120  proctable_get_from_array(size, array)
Line 126  proctable_get_from_array(size, array)
   
                 /* Process table is a list of process ended with NULL. */                  /* Process table is a list of process ended with NULL. */
                 ptbl = (PROCTABLE) realloc(ptbl,                  ptbl = (PROCTABLE) realloc(ptbl,
                                                                 (n_proc + 2) * sizeof(struct process *));                                  (n_proc + 2) * sizeof(struct process *));
                 if (ptbl == NULL) {                  if (ptbl == NULL) {
                         msg_error_print("realloc() failure\n");                          msg_error_print("realloc() failure\n");
                         return NULL;                          return NULL;
Line 140  proctable_get_from_array(size, array)
Line 146  proctable_get_from_array(size, array)
   
 #if DEBUG  #if DEBUG
                 msg_debug_print("proctable_get_from_array(): "                  msg_debug_print("proctable_get_from_array(): "
                                                                 "begin:end = %d:%d\n", begin_proc_id, end_proc_id);                                  "begin:end = %d:%d\n", begin_proc_id, end_proc_id);
 #endif  #endif
   
                 if (end_proc_id - begin_proc_id == 0) {                  if (end_proc_id - begin_proc_id == 0) {
Line 150  proctable_get_from_array(size, array)
Line 156  proctable_get_from_array(size, array)
                 }                  }
   
                 if (process_init_by_array(ptbl[n_proc],                  if (process_init_by_array(ptbl[n_proc],
                                                                         end_proc_id - begin_proc_id,                                          end_proc_id - begin_proc_id,
                                                                         array + begin_proc_id)) ;                                          array + begin_proc_id)) ;
                 else {                  else {
                         proctable_destroy(&ptbl);                          proctable_destroy(&ptbl);
                         return NULL;                          return NULL;
Line 266  proctable_update(ptbl)
Line 272  proctable_update(ptbl)
   
                                 /* Invalid link? */                                  /* Invalid link? */
                                 if (ptbl[i]->fd[k].link[j].proc_id                                  if (ptbl[i]->fd[k].link[j].proc_id
                                                                                 >= proctable_get_size(ptbl)) {                                                  >= proctable_get_size(ptbl)) {
                                         msg_error_print("invalid process number -- %d\n",                                          msg_error_print("invalid process number -- %d\n",
                                                                                         ptbl[i]->fd[k].link[j].proc_id);                                                          ptbl[i]->fd[k].link[j].proc_id);
                                         return -1;                                          return -1;
                                 }                                  }
   
                                 /* Selflink? */                                  /* Selflink? */
                                 if (i == ptbl[i]->fd[k].link[j].proc_id) {                                  if (i == ptbl[i]->fd[k].link[j].proc_id) {
                                         msg_error_print("cannot self link -- [%d].%s -> [%d].%s\n",                                          msg_error_print("cannot self 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;
                                 }                                  }
   
                                 /* Duplicated link? */                                  /* Duplicated link? */
                                 if (fd_is_proclink(&ptbl[i]->fd[k],                                  if (fd_is_proclink(&ptbl[i]->fd[k],
                                                                                         &ptbl[i]->fd[k].link[j]) - 1 != j) {                                                          &ptbl[i]->fd[k].link[j]) - 1 != j) {
                                         msg_error_print(                                          msg_error_print(
                                                                                         "duplicated link -- [%d].%s -> [%d].%s\n",                                                          "duplicated 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 324  proctable_update(ptbl)
Line 330  proctable_update(ptbl)
   
                                         }                                          }
                                         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;
                                 }                                  }
   
                                 /* If equivalent link doesn't exist, create it. */                                  /* If equivalent link doesn't exist, create it. */
                                 if (fd_is_proclink(&ptbl[ptbl[i]->fd[k].link[j].proc_id]->                                  if (fd_is_proclink(&ptbl[ptbl[i]->fd[k].link[j].proc_id]->
                                                                                         fd[ptbl[i]->fd[k].link[j].fd_id], &link))                                                          fd[ptbl[i]->fd[k].link[j].fd_id], &link))
                                         ;                                          ;
                                 else                                  else
                                         fd_add_proclink(&ptbl[ptbl[i]->fd[k].link[j].proc_id]->                                          fd_add_proclink(&ptbl[ptbl[i]->fd[k].link[j].proc_id]->
                                                                                         fd[ptbl[i]->fd[k].link[j].fd_id], &link);                                                          fd[ptbl[i]->fd[k].link[j].fd_id], &link);
                         }                          }
                 }                  }
         }          }
Line 354  proctable_create_pipes(ptbl)
Line 360  proctable_create_pipes(ptbl)
   
         for (i = 0; ptbl[i] != NULL; i++) {          for (i = 0; ptbl[i] != NULL; i++) {
                 for (k = 0; k < N_FD; k++) {                  for (k = 0; k < N_FD; k++) {
                         if (ptbl[i]->fd[k].n_link != 0) {                          /* XXX: We want to create pipes anyway. */
                           if (1 || ptbl[i]->fd[k].n_link != 0) {
                                 if (i == 0) {                                  if (i == 0) {
                                         /* Set the standart (basic) descriptors. */                                          /* Set the standart (basic) descriptors. */
                                         ptbl[0]->fd[k].pipe[0] = ptbl[0]->fd[k].pipe[1] = k;                                          ptbl[0]->fd[k].pipe[0] = ptbl[0]->fd[k].pipe[1] = k;
Line 362  proctable_create_pipes(ptbl)
Line 369  proctable_create_pipes(ptbl)
                                 else {                                  else {
 #if DEBUG  #if DEBUG
                                         msg_debug_print("creating pipe ptbl[%d]->fd[%d].pipe",                                          msg_debug_print("creating pipe ptbl[%d]->fd[%d].pipe",
                                                                                         i, k);                                                          i, k);
 #endif  #endif
   
                                         if (pipe(ptbl[i]->fd[k].pipe) < 0) {                                          if (pipe(ptbl[i]->fd[k].pipe) < 0) {
Line 374  proctable_create_pipes(ptbl)
Line 381  proctable_create_pipes(ptbl)
   
 #if DEBUG  #if DEBUG
                                         msg_print(" = (%d, %d)\n",                                          msg_print(" = (%d, %d)\n",
                                                                                         ptbl[i]->fd[k].pipe[0], ptbl[i]->fd[k].pipe[1]);                                                          ptbl[i]->fd[k].pipe[0], ptbl[i]->fd[k].pipe[1]);
 #endif  #endif
                                 }                                  }
                         }                          }
Line 405  proctable_exec(ptbl)
Line 412  proctable_exec(ptbl)
                                 /* Child process. */                                  /* Child process. */
                         case 0:                          case 0:
                                 for (k = 0; k < N_FD; k++)                                  for (k = 0; k < N_FD; k++)
                                         if (ptbl[i]->fd[k].n_link != 0) {                                          /* XXX: We want to dup pipe anyway. */
                                           if (1 || ptbl[i]->fd[k].n_link != 0) {
                                                 close(k);                                                  close(k);
                                                 dup(ptbl[i]->fd[k].pipe[k?1:0]);                                                  dup(ptbl[i]->fd[k].pipe[k ? 1 : 0]);
                                                   /* 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]);
                                                   */
                                           }
                                           else {
   #if DEBUG
                                                   msg_debug_print("proctable_exec(): "
                                                                   "process %d, fd %d, no links defined\n", i, k);
   #endif
                                         }                                          }
   
                                 for (j = 1; ptbl[j] != NULL; j++) {                                  for (j = 1; ptbl[j] != NULL; j++) {
                                         if (i != j)                                          if (1 || i != j)
                                                 for (k = 0; k < N_FD; k++) {                                                  for (k = 0; k < N_FD; k++) {
                                                         close(ptbl[j]->fd[k].pipe[0]);                                                          close(ptbl[j]->fd[k].pipe[0]);
                                                         close(ptbl[j]->fd[k].pipe[1]);                                                          close(ptbl[j]->fd[k].pipe[1]);
                                                 }                                                  }
                                 }                                  }
   /*
                                 for (k = 0; k < N_FD; k++)                                  for (k = 0; k < N_FD; k++)
                                         if (ptbl[i]->fd[k].n_link == 0)                                          if (ptbl[i]->fd[k].n_link == 0)
                                                 close(k);                                                  close(k);
   */
                                 execvp(ptbl[i]->argv[0], ptbl[i]->argv);                                  execvp(ptbl[i]->argv[0], ptbl[i]->argv);
                                 /*                                  /*
                                  * RETURN VALUES                                   * RETURN VALUES
Line 507  proctable_remove_process(p_ptbl, index)
Line 523  proctable_remove_process(p_ptbl, index)
         /* 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");
Line 534  proctable_print(ptbl)
Line 550  proctable_print(ptbl)
   
                 for (k = 0; k < N_FD; k++) {                  for (k = 0; k < N_FD; k++) {
                         msg_print("  %s = (%d, %d)\n", fd_str[0][k],                          msg_print("  %s = (%d, %d)\n", fd_str[0][k],
                                                                         ptbl[i]->fd[k].pipe[0], ptbl[i]->fd[k].pipe[1]);                                          ptbl[i]->fd[k].pipe[0], ptbl[i]->fd[k].pipe[1]);
                         for (j = 0; j < ptbl[i]->fd[k].n_link; j++)                          for (j = 0; j < ptbl[i]->fd[k].n_link; j++)
                                 msg_print("    [%d].%s %s [%d].%s\n",                                  msg_print("    [%d].%s %s [%d].%s\n",
                                                                                 i, fd_str[0][k],                                                  i, fd_str[0][k],
                                                                                 ((i&&k) || (!i&&!k)) ? "->" : "<-",                                                  ((i&&k) || (!i&&!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]);
                 }                  }
         }          }
 }  }
Line 555  proctable_read(p_ptbl, p_fds)
Line 571  proctable_read(p_ptbl, p_fds)
         char buf[BUFSIZE];          char buf[BUFSIZE];
   
         for (i = 0; (*p_ptbl)[i] != NULL; i++) {          for (i = 0; (*p_ptbl)[i] != NULL; i++) {
                 for (k = (i?1:0); k < (i?N_FD:1); k++) {                  for (k = (i ? 1 : 0); k < (i ? N_FD : 1); k++) {
                         if (FD_ISSET((*p_ptbl)[i]->fd[k].pipe[0], p_fds)) {                          if (FD_ISSET((*p_ptbl)[i]->fd[k].pipe[0], p_fds)) {
                                 register int j;                                  register int j;
   
                                 datasize = read((*p_ptbl)[i]->fd[k].pipe[0],                                  datasize = read((*p_ptbl)[i]->fd[k].pipe[0],
                                                                                 buf, BUFSIZE);                                                  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)                                  if (datasize == 0)
                                         close((*p_ptbl)[i]->fd[k].pipe[0]);                                          close((*p_ptbl)[i]->fd[k].pipe[0]);
Line 568  proctable_read(p_ptbl, p_fds)
Line 590  proctable_read(p_ptbl, p_fds)
                                 if (datasize < 0) {                                  if (datasize < 0) {
 #if DEBUG  #if DEBUG
                                         msg_debug_print("proctable_read(): "                                          msg_debug_print("proctable_read(): "
                                                                                         "read() failure, %d returned\n",                                                          "read() failure, %d returned\n",
                                                                                         datasize);                                                          datasize);
 #endif  #endif
                                         msg_errno_print();                                          msg_errno_print();
                                         msg_print("Terminating...");                                          msg_print("Terminating...");
Line 594  proctable_read(p_ptbl, p_fds)
Line 616  proctable_read(p_ptbl, p_fds)
                                                 p2.fd_id = (*p_ptbl)[i]->fd[k].link[j].fd_id;                                                  p2.fd_id = (*p_ptbl)[i]->fd[k].link[j].fd_id;
   
                                                 fd_remove_proclink(                                                  fd_remove_proclink(
                                                                                                 &(((*p_ptbl)[p2.proc_id])->fd[p2.fd_id]), &p1);                                                                  &(((*p_ptbl)[p2.proc_id])->fd[p2.fd_id]), &p1);
                                                 fd_remove_proclink(                                                  fd_remove_proclink(
                                                                                                 &(((*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])->                                                          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])->                                                          close(((*p_ptbl)[p2.proc_id])->
                                                                                                         fd[p2.fd_id].pipe[1]);                                                                          fd[p2.fd_id].pipe[1]);
   
                                         }                                          }
                                         else {                                          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)) {                                                  switch (write(fd_write, buf, datasize)) {
                                                         case -1:                                                          case -1:
 #if DEBUG  #if DEBUG
                                                                 msg_debug_print("proctable_read(): "                                                                  msg_debug_print("proctable_read(): "
                                                                                                                 "write() failed: %s\n",                                                                                  "write() failed: %s\n",
                                                                                                                 strerror(errno));                                                                                  strerror(errno));
 #endif  #endif
                                                                 break;                                                                  break;
                                                         case 0:                                                          case 0:
 #if DEBUG  #if DEBUG
                                                                 msg_debug_print("proctable_read(): "                                                                  msg_debug_print("proctable_read(): "
                                                                                                                 "write() returns 0: %s\n",                                                                                  "write() returns 0: %s\n",
                                                                                                                 strerror(errno));                                                                                  strerror(errno));
 #endif  #endif
                                                                 break;                                                                  break;
                                                         default:                                                          default:
Line 680  proctable_wait(p_ptbl)
Line 708  proctable_wait(p_ptbl)
                 switch (pid) {                  switch (pid) {
                         case -1:                          case -1:
                                 msg_error_print("proctable_wait(): "                                  msg_error_print("proctable_wait(): "
                                                                                 "waitpid() failure: %s\n", strerror(errno));                                                  "waitpid() failure: %s\n", strerror(errno));
                                 exit(1);                                  exit(1);
                                 break;                                  break;
   
                         case 0: // no child available                          case 0: // no child available
                                 msg_warn_print("proctable_wait(): "                                  msg_warn_print("proctable_wait(): "
                                                                                 "waitpid() warning: no child available\n");                                                  "waitpid() warning: no child available\n");
                                 break;                                  break;
   
                         default:                          default:
Line 696  proctable_wait(p_ptbl)
Line 724  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);                                                          index, pid);
   
                                         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))                                          if (WIFEXITED(status))
                                                 if (!WEXITSTATUS(status)) {                                                  if (!WEXITSTATUS(status)) {
Line 711  proctable_wait(p_ptbl)
Line 739  proctable_wait(p_ptbl)
                                                 }                                                  }
                                                 else {                                                  else {
                                                         msg_print("[%d] - error %d: %s - ",                                                          msg_print("[%d] - error %d: %s - ",
                                                                                                         pid,                                                                          pid,
                                                                                                         WEXITSTATUS(status),                                                                          WEXITSTATUS(status),
                                                                                                         strerror(                                                                          strerror(
                                                                                                                 WEXITSTATUS(status)));                                                                                  WEXITSTATUS(status)));
                                                         msg_array_print((*p_ptbl)[index]->argv);                                                          msg_array_print((*p_ptbl)[index]->argv);
                                                         msg_print("\n");                                                          msg_print("\n");
                                                 }                                                  }
   
                                         if (WIFSIGNALED(status)) {                                          if (WIFSIGNALED(status)) {
                                                 msg_print("[%d] - killed by signal %d - ",                                                  msg_print("[%d] - killed by signal %d - ",
                                                                                                 pid,                                                                  pid,
                                                                                                 WTERMSIG(status) );                                                                  WTERMSIG(status) );
                                                 msg_array_print((*p_ptbl)[index]->argv);                                                  msg_array_print((*p_ptbl)[index]->argv);
                                                 msg_print("\n");                                                  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");
 #endif  #endif
                                         proctable_remove_process(p_ptbl, index);                                          proctable_remove_process(p_ptbl, index);
 #if DEBUG  #if DEBUG
                                         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
                                 }                                  }
                                 break;                                  break;

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

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