Changeset 15796
- Timestamp:
- Dec 12, 2007, 12:18:25 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/pantasks/LocalJob.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/pantasks/LocalJob.c
r15031 r15796 15 15 16 16 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); 17 18 EmptyIOBuffer (&job[0].stdout_buff, 10, job[0].stdout_fd); 18 19 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); 19 21 close (job[0].stdout_fd); 20 22 close (job[0].stderr_fd); 21 23 } else { 22 24 /* 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); 23 26 while ((Nread = ReadtoIOBuffer (&job[0].stdout_buff, job[0].stdout_fd)) > 0); 24 27 switch (Nread) { … … 32 35 break; 33 36 } 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); 34 38 35 39 /* read stderr buffer */ … … 115 119 if (pipe (stderr_fd) < 0) goto pipe_error; 116 120 121 // XXX nothing to be read at this point 122 117 123 pid = fork (); 118 124 if (!pid) { /* must be child process */ … … 123 129 close (stderr_fd[0]); 124 130 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 125 137 /* tie our ends of the pipes to stdin, stdout, stderr */ 126 138 dup2 (stdout_fd[1], STDOUT_FILENO); … … 131 143 setvbuf (stderr, (char *) NULL, _IONBF, BUFSIZ); 132 144 145 // XXX allow the parent time to read the stdout/stderr buffers 146 usleep (10000); 147 133 148 status = execvp (job[0].argv[0], job[0].argv); 134 149 exit (1); … … 143 158 fcntl (stdout_fd[0], F_SETFL, O_NONBLOCK); 144 159 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 } 145 175 146 176 job[0].stdout_fd = stdout_fd[0];
Note:
See TracChangeset
for help on using the changeset viewer.
