[Qt-interest] error passing socket descriptors between applications
Thiago Macieira
thiago.macieira at trolltech.com
Mon Aug 17 15:47:04 CEST 2009
Em Segunda-feira 17 Agosto 2009, às 14:47:54, Thomi Richards escreveu:
> Hi,
>
> 2009/8/17 Thomi Richards <thomir at gmail.com>:
> > In my test application, this works perfectly. However, when I try and
> > replicate this in a larger application, It fails. The failure is in:
> >
> > qnativesocketengine_unix.cpp in the following code (line 674):
> >
> > EBADF means a bad file descriptor. I've checked, and I'm sure I'm
> > doing everything in my large application that I'm doing in my test
> > app. Can anyone suggest what might be the issue here? The socket
> > descriptor value seems OK to me - it's the original descriptor value +
> > 1, so the call to dup() is working.
>
> I have figured this out - and it's rather obvious - this works only if
> the call to dup() is before the call to QProcess::start(). If it's the
> other way around then the new child process does not inherit the open
> file descriptors of the parent.
>
> I can't seem to find a way around this, and since it's nothing to do
> with Qt, I guess I should go look elsewhere.
Child processes inherit things when they are started. Once they're spawned off,
they won't inherit anything.
Also note that you don't need to dup(2) the file descriptor. You can simply
unset the FD_CLOEXEC flag (see fcntl(2)). Be careful with multiple processes
starting: if you leak this file descriptor to more than one process, you'll
have trouble closing it.
--
Thiago Macieira - thiago.macieira (AT) nokia.com
Senior Product Manager - Nokia, Qt Development Frameworks
Sandakerveien 116, NO-0402 Oslo, Norway
Qt Developer Days 2009 | Registration Now Open!
Munich, Germany: Oct 12 - 14 San Francisco, California: Nov 2 - 4
http://qt.nokia.com/qtdevdays2009
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090817/4ce597e8/attachment.bin
More information about the Qt-interest-old
mailing list