IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15796


Ignore:
Timestamp:
Dec 12, 2007, 12:18:25 PM (18 years ago)
Author:
eugene
Message:

added an extra read from stdout/stderr when starting a local job; this clears clutter waiting on the line from the forked child. a usleep 10ms in the child block before the exec prevents the read from stealing output from the execed child process

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/pantasks/LocalJob.c

    r15031 r15796  
    1515
    1616  if ((job[0].state == JOB_EXIT) || (job[0].state == JOB_CRASH)) {
     17    if (DEBUG) fprintf (stderr, "empty buffer 0: (%x) %d of %d\n", job[0].stdout_buff.buffer, job[0].stdout_buff.Nbuffer, job[0].stdout_buff.Nalloc);
    1718    EmptyIOBuffer (&job[0].stdout_buff, 10, job[0].stdout_fd);
    1819    EmptyIOBuffer (&job[0].stderr_buff, 10, job[0].stderr_fd);
     20    if (DEBUG) fprintf (stderr, "empty buffer 1: (%x) %d of %d\n", job[0].stdout_buff.buffer, job[0].stdout_buff.Nbuffer, job[0].stdout_buff.Nalloc);
    1921    close (job[0].stdout_fd);
    2022    close (job[0].stderr_fd);
    2123  } else {
    2224    /* read stdout buffer */
     25    if (DEBUG) fprintf (stderr, "read buffer 0: (%x) %d of %d\n", job[0].stdout_buff.buffer, job[0].stdout_buff.Nbuffer, job[0].stdout_buff.Nalloc);
    2326    while ((Nread = ReadtoIOBuffer (&job[0].stdout_buff, job[0].stdout_fd)) > 0);
    2427    switch (Nread) {
     
    3235        break;
    3336    }
     37    if (DEBUG) fprintf (stderr, "read buffer 1: (%x) %d of %d\n", job[0].stdout_buff.buffer, job[0].stdout_buff.Nbuffer, job[0].stdout_buff.Nalloc);
    3438 
    3539    /* read stderr buffer */
     
    115119  if (pipe (stderr_fd) < 0) goto pipe_error;
    116120
     121  // XXX nothing to be read at this point
     122
    117123  pid = fork ();
    118124  if (!pid) { /* must be child process */
     
    123129    close (stderr_fd[0]);
    124130
     131    // XXX neither of these work to empty the child stdout buffer
     132    // fflush (stdout);
     133    // fflush (stderr);
     134    // close (STDOUT_FILENO);
     135    // close (STDERR_FILENO);
     136
    125137    /* tie our ends of the pipes to stdin, stdout, stderr */
    126138    dup2 (stdout_fd[1], STDOUT_FILENO);
     
    131143    setvbuf (stderr, (char *) NULL, _IONBF, BUFSIZ);
    132144
     145    // XXX allow the parent time to read the stdout/stderr buffers
     146    usleep (10000);
     147
    133148    status = execvp (job[0].argv[0], job[0].argv);
    134149    exit (1);
     
    143158  fcntl (stdout_fd[0], F_SETFL, O_NONBLOCK);
    144159  fcntl (stderr_fd[0], F_SETFL, O_NONBLOCK);
     160
     161  // XXX There seems to always be extra data on the pipe, specifically the
     162  // stdout buffer from the parent.  If I read it here, then it clears out that data.
     163  // But, how can I be sure I will not start reading data from the exec-ed process?
     164
     165  { // test read of the stdout buffer
     166    int Nread;
     167    char buffer[0x1000];
     168
     169    Nread = read (stdout_fd[0], buffer, 0x1000);
     170    if (DEBUG) fprintf (stderr, "read from stdout before exec: %d bytes\n", Nread);
     171
     172    Nread = read (stderr_fd[0], buffer, 0x1000);
     173    if (DEBUG) fprintf (stderr, "read from stderr before exec: %d bytes\n", Nread);
     174  }
    145175
    146176  job[0].stdout_fd = stdout_fd[0];
Note: See TracChangeset for help on using the changeset viewer.