IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33300


Ignore:
Timestamp:
Feb 16, 2012, 6:37:16 PM (14 years ago)
Author:
eugene
Message:

adding rconnect handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/load_catalogs.c

    r33298 r33300  
    11# include "relphot.h"
     2# include <sys/types.h>
     3# include <sys/wait.h>
    24
    35// this function loops over the catalogs, loads the data, and extracts a bright subset
     
    106108  }   
    107109
     110  char *cwd;
     111  if ((cwd = getcwd(NULL, 1024)) == NULL) {
     112    fprintf (stderr, "error getting cwd (longer than 1024 chars?)\n");
     113    exit (1);
     114  }
     115
    108116  int i;
    109117  for (i = 0; i < table->Nhosts; i++) {
     118
     119    // if table->hosts[i].pathname is a relative path (pathname[0] is not '/'), then
     120    // we need to prepend our current path
     121
     122    if (table->hosts[i].pathname[0] != '/') {
     123      int Nbytes = strlen(cwd) + strlen(table->hosts[i].pathname) + 2;
     124      char *newpath = NULL;
     125      ALLOCATE (newpath, char, Nbytes);
     126      snprintf (newpath, Nbytes, "%s/%s", cwd, table->hosts[i].pathname);
     127      free (table->hosts[i].pathname);
     128      table->hosts[i].pathname = newpath;
     129    }
    110130
    111131    char catalogFile[512];
     
    162182      }
    163183      table->hosts[i].pid = pid; // save for future reference
    164       // check that all hosts started OK?
    165184    }
    166185  }
     
    169188    fprintf (stderr, "run the relphot_client commands above.  when these are done, hit return\n");
    170189    getchar();
    171   } else {
    172     // watch for stdout / stderr from those jobs...
    173     // wait for all of them to complete...
     190  }
     191  if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) {
     192    // we have launched table->Nhosts jobs; wait for all of them to complete...
     193    for (i = 0; i < table->Nhosts; i++) {
     194      int status = 0;
     195      int pid = waitpid (-1, &status, 0);
     196
     197      // XXX we'll need to pass in WNOHANG and keep retrying if we want to have a timeout...
     198      // find the host which has finished
     199      int j;
     200      for (j = 0; j < table->Nhosts; j++) {
     201        if (table->hosts[j].pid != pid) continue;
     202        // check on the status of this and report any output?
     203        fprintf (stderr, "job finished for %s (%d)\n", table->hosts[j].hostname, pid);
     204        if (WIFEXITED(status)) {
     205          fprintf (stderr, "normal completion, exit status is %d\n", WEXITSTATUS(status));
     206          if (WEXITSTATUS(status)) {
     207            fprintf (stderr, "job failed on %s\n", table->hosts[j].hostname);
     208          }
     209        }
     210        // read the stderr and stdout
     211        IOBuffer buffer;
     212        InitIOBuffer (&buffer, 100);
     213        EmptyIOBuffer (&buffer, 100, table->hosts[j].stdio[1]);
     214        fprintf (stderr, "--- stdout from %s ---\n", table->hosts[j].hostname);
     215        write (STDOUT_FILENO, buffer.buffer, buffer.Nbuffer);
     216        fprintf (stderr, "\n");
     217         
     218        InitIOBuffer (&buffer, 100);
     219        EmptyIOBuffer (&buffer, 100, table->hosts[j].stdio[2]);
     220        fprintf (stderr, "--- stderr from %s ---\n", table->hosts[j].hostname);
     221        write (STDOUT_FILENO, buffer.buffer, buffer.Nbuffer);
     222        fprintf (stderr, "\n");
     223      }
     224    }
    174225  }
    175226
Note: See TracChangeset for help on using the changeset viewer.