[Qt-interest] QProcess could close the reading pipe, thus killing the child process with SIGPIPE
Jan Kundrát
jkt at gentoo.org
Sun May 3 13:45:21 CEST 2009
Dear list,
I've been facing a werid issue with QProcess -- sometimes the launched
process would get SIGPIPE when writing to its stdout which I'm reading
from, although I don't close it myself (and am in fact still reading
from it). After days of pondering about what's going wrong, I've come to
a suspicious code in qprocess.cpp,
QProcessPrivate::_q_canReadStandardOutput (and the same for
StandardError). It reads:
qint64 available = bytesAvailableFromStdout();
if (available == 0) {
if (stdoutChannel.notifier)
stdoutChannel.notifier->setEnabled(false);
destroyPipe(stdoutChannel.pipe);
#if defined QPROCESS_DEBUG
qDebug("QProcessPrivate::canReadStandardOutput(), 0 bytes
available");
#endif
return false;
}
After enabling that qDebug call, I see that this usually happens during
app termination (perhaps in ~QProcess()), so the intent of this code is
probably to "close the pipes cleanly". However, I've seen that error
even during normal operation, and it immediately resulted in the child
process getting killed by SIGPIPE. Simply changing that to the following
works:
qint64 available = bytesAvailableFromStdout();
if (available == 0) {
/*if (stdoutChannel.notifier)
stdoutChannel.notifier->setEnabled(false);
destroyPipe(stdoutChannel.pipe);*/
#if 1
qDebug("QProcessPrivate::canReadStandardOutput(), 0 bytes
available");
#endif
return false;
}
Occasionally I'd get the message about zero bytes, but nothing bad
happens -- the process is still usable, signals get emitted, both
reading and writing works.
Note that a similar problem exists in the StdError handling.
So now I wonder if the Trolls could confirm that it's indeed a problem
in QProcess, or that I'm misusing the class in a wrong way. I'd
appreciate any response from people familiar with this code or a pointer
about where to report this issue.
Cheers,
-jkt
--
cd /local/pub && more beer > /dev/mouth
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090503/83615178/attachment.bin
More information about the Qt-interest-old
mailing list