IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 4, 2005, 5:35:47 PM (21 years ago)
Author:
eugene
Message:

substantial dev work on scheduler/pcontrol/pclient

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/pcontrol/GetJobOutput.c

    r3212 r4450  
    11# include "pcontrol.h"
     2# define PCLIENT_TIMEOUT 20
    23
    3 int GetJobOutput (Job *job, char *channel) {
     4/* we read Nbytes from the host, then watch for the prompt */
     5int GetJobOutput (char *command, Host *host, IOBuffer *buffer, int Nbytes) {
    46 
    5   int      status;
    6   IOBuffer *buffer;
    7   Host     *host;
     7  int i, status, Nstart;
     8  char *line;
    89
    9   buffer = NULL;
    10   if (!strcasecmp (channel, "stdout")) buffer = &job[0].stdout;
    11   if (!strcasecmp (channel, "stderr")) buffer = &job[0].stderr;
    12   if (buffer == NULL) {
    13     fprintf (stderr, "invalid output channel : programming error\n");
    14     exit (1);
     10  /* flush any earlier messages */
     11  ReadtoIOBuffer (buffer, host[0].stdout);
     12  FlushIOBuffer (buffer);
     13  Nstart = buffer[0].Nbuffer;
     14
     15  /* send command (stdout / stderr) */
     16  ALLOCATE (line, char, MAX (1, strlen(command) + 1));
     17  sprintf (line, "%s\n", command);
     18  status = write (host[0].stdin, line, strlen(line));
     19  free (line);
     20
     21  /* is pipe still open? */
     22  if ((status == -1) && (errno == EPIPE)) return (PCLIENT_DOWN);
     23
     24  /* read at least Nbytes, then watch for PCLIENT_PROMPT */
     25  line = NULL;
     26  status = -1;
     27  for (i = 0; (i < PCLIENT_TIMEOUT) && (status == -1) && (line == NULL); i++) {
     28    status = ReadtoIOBuffer (buffer, host[0].stdout);
     29    if ((buffer[0].Nbuffer - Nstart) >= Nbytes) {
     30      line = memstr (buffer[0].buffer, PCLIENT_PROMPT, buffer[0].Nbuffer);
     31    }
     32    if (status == -1) usleep (10000);
    1533  }
    16 
    17   /* If we already have the output, just return, don't retry */
    18   if (buffer[0].Nbuffer) return (TRUE);
    19 
    20   /** must have a valid host : if not, move to pending? **/
    21   host = job[0].host;
    22   status = PclientCommand (host, channel, PCLIENT_PROMPT, buffer);
     34  if (status ==  0) return (PCLIENT_DOWN);
     35  if (status == -1) return (PCLIENT_HUNG);
    2336
    2437  /* check on success of pclient command */
    2538  switch (status) {
    26     case PCLIENT_DOWN:
    27       /*** different behavior for ANYHOST, WANTHOST, NEEDHOST ***/
    28       buffer[0].Nbuffer = 0;
     39    case -1:
     40      fprintf (stderr, "host %s is not responding\n", host[0].hostname);
     41      return (FALSE);
     42
     43    case 0:
    2944      fprintf (stderr, "host %s is down\n", host[0].hostname);
    3045      return (FALSE);
    3146
    32     case PCLIENT_HUNG:
    33       /*** should we consider a HUNG host DOWN? ***/
    34       buffer[0].Nbuffer = 0;
    35       fprintf (stderr, "host %s is not responding\n", host[0].hostname);
    36       return (FALSE);
    37 
    38     case PCLIENT_GOOD:
    39       fprintf (stderr, "message received (GetJobOutput : %s)\n", channel); 
     47    default:
     48      fprintf (stderr, "message received (GetJobOutput : %s)\n", command); 
     49      /* drop extra bytes from pclient (not pclient:job) */
     50      buffer[0].Nbuffer = Nstart + Nbytes;
     51      if (buffer[0].Nalloc > buffer[0].Nbuffer) {
     52        bzero (buffer[0].buffer + buffer[0].Nbuffer, buffer[0].Nalloc - buffer[0].Nbuffer);
     53      }
    4054      return (TRUE);
    41 
    42     default:
    43       fprintf (stderr, "unknown status for pclient command: programming error\n"); 
    44       exit (1);
    4555  }
    4656
Note: See TracChangeset for help on using the changeset viewer.