From: Philippe E. <ph...@us...> - 2002-10-19 00:36:56
|
Update of /cvsroot/oprofile/oprofile/libutil++ In directory usw-pr-cvs1:/tmp/cvs-serv13579/libutil++ Modified Files: child_reader.cpp Log Message: getline() finished too early when child process write on stderr. regards, Phil Index: child_reader.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/libutil++/child_reader.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- child_reader.cpp 18 Oct 2002 01:26:33 -0000 1.10 +++ child_reader.cpp 19 Oct 2002 00:36:54 -0000 1.11 @@ -126,8 +126,13 @@ FD_SET(fd2, &read_fs); if (select(max(fd1, fd2) + 1, &read_fs, 0, 0, 0) >= 0) { - if (FD_ISSET(fd1, &read_fs)) - end1 = read(fd1, buf1, PIPE_BUF); + if (FD_ISSET(fd1, &read_fs)) { + ssize_t temp = read(fd1, buf1, PIPE_BUF); + if (temp >= 0) + end1 = temp; + else + end1 = 0; + } if (FD_ISSET(fd2, &read_fs)) { if (end2 >= sz_buf2) { @@ -158,7 +163,9 @@ bool ok = true; bool ret = true; + bool can_stop = false; do { + int temp = end2; if (pos1 >= end1) { pos1 = 0; ret = block_read(); @@ -175,8 +182,17 @@ // !ok ==> endl has been read so do not copy it. result.append(&buf1[pos1], (temp_pos - pos1) - !ok); + if (!ok || !end1) + can_stop = true; + + // reading zero byte from stdout don't mean than we exhausted + // all stdout output, we must continue to try until reading + // stdout and stderr return zero byte. + if (ok && temp != end2) + can_stop = false; + pos1 = temp_pos; - } while (ok && end1); + } while (!can_stop); // Is this correct ? return end1 != 0 || result.length() != 0; |