IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33369


Ignore:
Timestamp:
Feb 24, 2012, 2:28:07 PM (14 years ago)
Author:
eugene
Message:

handle failures more gracefully

Location:
branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/CopyToHostLocation.c

    r33368 r33369  
    9292    valid:
    9393      // read srcname, write to tgtname, get MD5 sum for srcname as we go:
     94      // XXX files that fail here should be skipped (but don't give up)
    9495      if (!get_md5_with_copy (srcname, tgtname, srcDigest)) {
    9596        fprintf (stderr, "error reading %s, getting md5, or writing %s\n", srcname, tgtname);
     
    99100       
    100101      // need to re-open and re-read tgtname to check md5sum
     102      // XXX files that fail here need to be checked
    101103      char *absname = abspath (tgtname, 1024);
    102104      if (!get_md5_from_pclient (host, absname, tgtDigest)) {
     
    233235  // fprintf (stderr, "command: %s\n", line);
    234236
    235   // start the md5sum command
    236237  InitIOBuffer (&buffer, 100);
    237   PclientCommand (host, line, &buffer);
    238   PclientResponse (host, PCLIENT_PROMPT, &buffer);
    239   // XXX for the moment, abort if anything goes wrong
    240 
    241   // wait for result
    242238  InitIOBuffer (&stdout_buf, 100);
    243239  InitIOBuffer (&stderr_buf, 100);
     240
     241  // need to reset pclient for next command...
     242  if (!PclientCommand (host, "reset", &buffer)) goto escape;
     243  if (!PclientResponse (host, PCLIENT_PROMPT, &buffer)) goto escape;
     244  FlushIOBuffer (&buffer);
     245
     246  // start the md5sum command
     247  if (!PclientCommand (host, line, &buffer)) goto escape;
     248  if (!PclientResponse (host, PCLIENT_PROMPT, &buffer)) goto escape;
     249  // XXX for the moment, abort if anything goes wrong
     250
     251  // wait for result
    244252  while (!CheckBusyJob (host, &stdout_buf, &stderr_buf)) {
     253    FlushIOBuffer (&stdout_buf);
     254    FlushIOBuffer (&stdout_buf);
    245255    usleep (10000);
    246256  }
    247257  if (stderr_buf.Nbuffer) {
    248258    fprintf (stderr, "error in md5sum: %s\n", stderr_buf.buffer);
    249     exit (1);
     259    goto escape;
    250260  }
    251261
     
    267277 
    268278  // need to reset pclient for next command...
    269   PclientCommand (host, "reset", &buffer);
    270   PclientResponse (host, PCLIENT_PROMPT, &buffer);
     279  if (!PclientCommand (host, "reset", &buffer)) goto escape;
     280  if (!PclientResponse (host, PCLIENT_PROMPT, &buffer)) goto escape;
    271281
    272282  return TRUE;
     283
     284escape:
     285  FreeIOBuffer (&buffer);
     286  FreeIOBuffer (&stdout_buf);
     287  FreeIOBuffer (&stderr_buf);
     288  return FALSE;
    273289}
    274290
  • branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/PclientCommands.c

    r33368 r33369  
    2020  if ((status == -1) && (errno == EPIPE)) {
    2121    fprintf (stderr, "pclient read gives pipe error for %s\n", command);
    22     abort();
     22    return FALSE;
    2323  }
    2424
     
    5353  if (status ==  0) {
    5454    fprintf (stderr, "pclient read returns 0 for %s\n", response);
    55     abort();
     55    return FALSE;
    5656  }
    5757  assert (line != NULL); // return (PCLIENT_HUNG);
     
    6565int GetJobOutput (char *command, HostInfo *host, IOBuffer *output, int size) {
    6666 
    67   char *line;
    68   int i, status;
    69   struct timespec request, remain;
     67    char *line;
     68    int i, status;
     69    struct timespec request, remain;
    7070
    71   InitIOBuffer (output, 100);
     71    /* avoid blocking on waitpid, test every 100 usec, up to 10 msec */
     72    request.tv_sec = 0;
     73    request.tv_nsec = 100000;
    7274
    73   /* avoid blocking on waitpid, test every 100 usec, up to 10 msec */
    74   request.tv_sec = 0;
    75   request.tv_nsec = 100000;
     75    status = write_fmt (host->stdio[0], "%s\n", command);
    7676
    77   status = write_fmt (host->stdio[0], "%s\n", command);
     77    if ((status == -1) && (errno == EPIPE)) {
     78        fprintf (stderr, "host crashed?\n");
     79        goto escape;
     80    }
    7881
    79   if ((status == -1) && (errno == EPIPE)) {
    80     fprintf (stderr, "host crashed\n");
    81     exit (2);
    82   }
     82    // attempt to read the output->size bytes from the host
     83    for (i = 0; (i < PCLIENT_TIMEOUT) && (status != 0) && (output->Nbuffer < size); i++) {
     84        status = ReadtoIOBuffer (output, host->stdio[1]);
     85        if (status == -1) nanosleep (&request, &remain);
     86    }
     87    if (DEBUG) fprintf (stderr, "Read %d of %d bytes so far\n", output->Nbuffer, size);
     88    if (status == 0) {
     89        fprintf (stderr, "client down\n");
     90        goto escape;
     91    }
     92    if (output->Nbuffer < size) {
     93        fprintf (stderr, "client hung\n");
     94        goto escape;
     95    }
    8396
    84   // attempt to read the output->size bytes from the host
    85   for (i = 0; (i < PCLIENT_TIMEOUT) && (status != 0) && (output->Nbuffer < size); i++) {
    86     status = ReadtoIOBuffer (output, host->stdio[1]);
    87     if (status == -1) nanosleep (&request, &remain);
    88   }
    89   if (DEBUG) fprintf (stderr, "Read %d of %d bytes so far\n", output->Nbuffer, size);
    90   assert (status != 0);            // return PCLIENT_DOWN;
    91   assert (output->Nbuffer >= size); // return PCLIENT_HUNG;
     97    // keep trying to read until we get the prompt
     98    line = NULL;
     99    status = -1;
     100    for (i = 0; (i < PCLIENT_TIMEOUT) && (status != 0) && (line == NULL); i++) {
     101        status = ReadtoIOBuffer (output, host->stdio[1]);
     102        line = memstr (output->buffer, PCLIENT_PROMPT, output->Nbuffer);
     103        if (status == -1) nanosleep (&request, &remain);
     104    }
     105    if (DEBUG) fprintf (stderr, "Read %d of %d bytes so far\n", output->Nbuffer, size);
     106    if (!status) {
     107        fprintf (stderr, "pclient down?\n");          // return PCLIENT_DOWN;
     108        goto escape;
     109    }
     110    if (!line) {
     111        fprintf (stderr, "pclient hung?\n");                  // return PCLIENT_HUNG;
     112        goto escape;
     113    }
     114    return TRUE;
    92115
    93   // keep trying to read until we get the prompt
    94   line = NULL;
    95   status = -1;
    96   for (i = 0; (i < PCLIENT_TIMEOUT) && (status != 0) && (line == NULL); i++) {
    97     status = ReadtoIOBuffer (output, host->stdio[1]);
    98     line = memstr (output->buffer, PCLIENT_PROMPT, output->Nbuffer);
    99     if (status == -1) nanosleep (&request, &remain);
    100   }
    101   if (DEBUG) fprintf (stderr, "Read %d of %d bytes so far\n", output->Nbuffer, size);
    102   assert (status != 0);       // return PCLIENT_DOWN;
    103   assert (line);                      // return PCLIENT_HUNG;
    104   return TRUE;
     116escape:
     117    return FALSE;
    105118}
    106119
     
    120133  if (p == NULL) {
    121134    if (DEBUG) fprintf (stderr, "missing STATUS in response; try again?\n");
     135    FreeIOBuffer (&buffer);
    122136    return FALSE;
    123137  }
     
    129143  if (!strcmp(string, "BUSY")) {
    130144    if (DEBUG) fprintf (stderr, "not yet done...\n");
     145    FreeIOBuffer (&buffer);
    131146    return FALSE;
    132147  }
     
    135150  if (!strcmp(string, "CRASH")) {
    136151    fprintf (stderr, "crash on host...\n");
    137     exit (1);
     152    FreeIOBuffer (&buffer);
     153    return FALSE;
    138154  }
    139155
     
    158174  } else {
    159175    ReadtoIOBuffer (&buffer, host->stdio[1]);
    160     FlushIOBuffer (&buffer);
    161176  }
    162177  if (stderr_buf_size) {
     
    164179  } else {
    165180    ReadtoIOBuffer (&buffer, host->stdio[2]);
    166     FlushIOBuffer (&buffer);
    167181  }
    168182
     183  FreeIOBuffer (&buffer);
    169184  return TRUE;
    170185}
Note: See TracChangeset for help on using the changeset viewer.