[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 15:37:41 CEST 2009


Thiago Macieira wrote:
> It's not a problem.
> 
> That slot should not be called unless there's something to be read. If 
> there's a read of 0, that means the pipe has closed. So the code is right.

Hi Thiago,
OK, that makes sense. I've tried to go through the Qt sources to a call
to select() or poll(), but it's probably buried deep inside the glib
event loop, so I gave up. Let's assume for a while that the OS is
correct for a while.

This QProcess is created in a separate thread. This thread has its own
event loop and I'm not touching the process in any other thread at all.
I've attached the relevant code, but let me explain what it is supposed
to do:

* There's a QueuedConnection between the readyReady() and one method
* That method does only "if ( socket->canReadLine() ) processLine(
socket->readLine() );"
* The processLine is a bit more complex; due to the nature of the
protocol in question, we don't know whether we will have to read some
more data before that line is processed. That means that from inside a
(queued) slot connected to readyRead, we sometimes call
waitForReadyRead(), read(size) and readLine(). Is that safe?

If there's no bug in my OS, I'd guess that somehow I managed to read the
data that interrupted the select() deep inside the event loop. However,
I don't see how that could happen, given that the event loop should run
in the same thread as my handler (right?). Is that a possible scenario?

If the above is correct, I could refactor the code to use yet another
buffer and avoid working with the QProcess from the (queued) event
handler, but it doesn't look like the right solution to me. I'm open to
suggestions, though.

Full code is at [1], I'm attaching the relevant parts.

> There should be no activation with 0 bytes except for the EOF. If there 
> is, it's a bug in your operating system.

It's a linux box with kernel 2.6.26-gentoo-r1.

Cheers,
-jkt

[1]
http://repo.or.cz/w/trojita.git?a=blob;f=Imap/Parser/Parser.cpp;h=29af0f2c926bfe477572164c2005aea193393ac1;hb=HEAD

-- 
cd /local/pub && more beer > /dev/mouth
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dealing-with-qprocess.cpp
Type: text/x-c++src
Size: 3956 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090503/e74e104c/attachment.bin 
-------------- 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/e74e104c/attachment-0001.bin 


More information about the Qt-interest-old mailing list