IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33474


Ignore:
Timestamp:
Mar 10, 2012, 12:49:50 PM (14 years ago)
Author:
eugene
Message:

adding HostTablewait function which harvests I/O as it goes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/HostTable.c

    r33375 r33474  
    188188  return TRUE;
    189189}
     190
     191// wait for all children to complete, report output to stdout
     192int HostTableWaitJobsGetIO (HostTable *table, char *file, int lineno) {
     193
     194  int i;
     195
     196  // we have launched table->Nhosts jobs; wait for all of them to complete...
     197  // if one (N) failed to launch, we will get an ECHILD error from the last (N) calls
     198
     199  // we need to read any data waiting on stderr or stdout from these jobs, or the overfull
     200  // buffers can cause a problem.  we alternate between 'select' and 'waitpid' calls with
     201  // timeouts for both
     202
     203  while (1) {
     204
     205    // is anyone done?
     206    int status = 0;
     207
     208    // XXX we'll need to pass in WNOHANG and keep retrying if we want to have a timeout...
     209    int pid = waitpid (-1, &status, WNOHANG);
     210    if (pid) {
     211      if (pid == -1) {
     212        switch (errno) {
     213          case ECHILD:
     214            done = TRUE;
     215            // no more children, need to exit ...
     216            break;
     217          default:
     218            fprintf (stderr, "programming error (2)? %s %d", file, lineno);
     219            exit (2);
     220        }
     221      } else {
     222        // handle
     223     
     224
     225
     226    // find the host which has finished
     227    int j;
     228    int found = FALSE;
     229    for (j = 0; j < table->Nhosts; j++) {
     230      if (table->hosts[j].pid != pid) continue;
     231      found = TRUE;
     232      // check on the status of this and report any output?
     233      fprintf (stderr, "job finished for %s (%d)\n", table->hosts[j].hostname, pid);
     234      // read the stderr and stdout
     235      IOBuffer buffer;
     236      InitIOBuffer (&buffer, 100);
     237      EmptyIOBuffer (&buffer, 100, table->hosts[j].stdio[1]);
     238      fprintf (stderr, "--- stdout from %s ---\n", table->hosts[j].hostname);
     239      write (STDOUT_FILENO, buffer.buffer, buffer.Nbuffer);
     240      fprintf (stderr, "\n");
     241         
     242      InitIOBuffer (&buffer, 100);
     243      EmptyIOBuffer (&buffer, 100, table->hosts[j].stdio[2]);
     244      fprintf (stderr, "--- stderr from %s ---\n", table->hosts[j].hostname);
     245      write (STDOUT_FILENO, buffer.buffer, buffer.Nbuffer);
     246      fprintf (stderr, "\n");
     247      if (WIFEXITED(status)) {
     248        fprintf (stderr, "normal completion, exit status is %d\n", WEXITSTATUS(status));
     249        table->hosts[j].status = WEXITSTATUS(status);
     250        if (table->hosts[j].status) {
     251          fprintf (stderr, "job failed on %s\n", table->hosts[j].hostname);
     252          continue;
     253        }
     254      } else {
     255        table->hosts[j].status = -1;
     256        fprintf (stderr, "job exited abnormally on %s\n", table->hosts[j].hostname);
     257        continue;
     258      }
     259    }
     260    if (!found) {
     261      fprintf (stderr, "Programming error: failed to matched finished job to known host!\n");
     262      exit (2);
     263    }
     264  }
     265  return TRUE;
     266}
Note: See TracChangeset for help on using the changeset viewer.