int ofd, efd;
fd_set rfds;
int maxfd;
+ int eof = 0;
char stdoutstr[32], stderrstr[32], indent[16] = { " " };
indent[get_parent_count() + 1] = 0;
FD_SET(ofd, &rfds);
FD_SET(efd, &rfds);
- while (1) {
+ while (!eof) {
char *sptr , *eptr;
char rbuf[BUF_SIZE];
int bytes;
pr_err("read() failed: %s\n", strerror(error));
break;
}
- if (bytes == 0)
- break;
+
+ /*
+ * Workaround: When a process had die and it has only
+ * written to stderr, select() doesn't indicate that
+ * there might be something to read in stderr fd. To
+ * work around this issue, we try to read stderr just
+ * in case in order to ensure everything gets read.
+ */
+ if (bytes == 0) {
+ bytes = read(efd, rbuf, BUF_SIZE);
+ typestr = stderrstr;
+ eof = 1;
+ }
sptr = eptr = rbuf;
while(bytes--) {