Re: Newbie problems using g_spawn_async_with_pipes and watching for IO

On Wed, 20 Feb 2013 18:42:28 -0000
"William Orr" <ay1244 gmail com> wrote:
Chris Vine wrote:

On Tue, 19 Feb 2013 20:28:16 -0500
Will Orr <ay1244 gmail com> wrote:
    > Here[1] is the problematic code.
    > I'm trying to run a command and gather the output and return
    code. I
    > do this by watching for the process to return, as well as
    waiting for
    > the channels to HUP. However, my callbacks never get called with
    > set to G_IO_HUP, even after the process terminates. Nor do any
    of the
    > g_io_channel_read_* calls return errors. This seems inconsistent
    > the documentation, as well as examples that I've found in the
    hours of
    > researching this problem.
    > I'm clearly doing something wrong, I'm just not sure where yet.
    > advice or solutions would be great. Thanks so much! Let me know
    if I
    > need to provide anymore information. Please CC me, as I'm not a
    > of this list.

This will help you:


Is this really preferable to using g_io_add_watch? It doesn't seem
like I can make use of that in my event loop…

I think you misunderstood me, and I can see that I was was overly
concise. g_poll() is a wrapper on unix-like OSes for poll().  The web
page to which I directed you explains why POLLHUP, and so G_IO_HUP, is
not a reliable indicator of end-of-file.

If you have received G_IO_HUP, you must have received a hang-up, which
means on a pipe file descriptor that you must have end-of-file.  However
the converse is not true.  You can have end-of-file without G_IO_HUP,
which is what you are experiencing.  You are receiving POLLIN/G_IO_IN

The only reliable way of detecting end-of-file is if read() returns 0.
This equates to one of the GIOChannel read functions returning a
GIOStatus value of G_IO_STATUS_EOF.  Your mistake was in not checking
return values.

I have not studied your code in detail but you do not seem to be
unref()ing consistently either, in particularly in a case of error.  The
best thing to do is to unref() the GIOChannel object as soon as you have
called g_io_add_watch() or g_source_attach().  Then, returning FALSE in
the callback will automatically release the object and its resources.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]