Distinguish between G_IO_ERR and G_IO_HUP

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Distinguish between G_IO_ERR and G_IO_HUP

Colossus
Hi,

I'm trying to catch the returned error message of the unzip
executable with GIOChannel. I use g_spawn_async_with_pipes and
then I create a GIOChannel and then i call g_io_add_watch. I run
unzip with an incomplete zip file so the have the unzip executable
fails with an error message but the G_IO_ERR conditions is never met,
while the G_IO_HUP is met when both the pipe ends and when the unzip
returns an error; how can I distinguish the two conditions so to have
my application emits an appropriate gtk_dialog with an error message
when unzip fails to open the zip archive ?
--
Colossus

Cpsed, a Linux OpenGL 3D scene editor
http://cpsed.sourceforge.net/

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Distinguish between G_IO_ERR and G_IO_HUP

Tim Muller
On Monday 30 May 2005 13:31, Colossus wrote:

> I'm trying to catch the returned error message of the unzip
> executable with GIOChannel. I use g_spawn_async_with_pipes and
> then I create a GIOChannel and then i call g_io_add_watch. I run
> unzip with an incomplete zip file so the unzip executable
> fails with an error message but the G_IO_ERR condition is never met,
> while the G_IO_HUP is met when both the pipe ends and when the unzip
> returns an error; how can I distinguish the two conditions so to have
> my application emits an appropriate gtk_dialog with an error message
> when unzip fails to open the zip archive ?

The G_IO_ERR condition only occurs if there is an error on the pipe/iochannel.
It has nothing to do with the child program being executed. To catch an error
in your spawned unzip program, you'll need to:

 * pass the G_SPAWN_DO_NOT_REAP_CHILD flag to g_spawn_*
 * watch the child yourself via g_child_watch_add ()

When the child exits, the callback function you passed to g_child_watch_add()
is called with the exit status of the child, which will tell you if the child
exited with an error or not. On unix, you'll need the macros described in the
waitpid manpage to interpret the exit code (e.g. if (WIFEXITED(status) &&
WEXITSTATUS(status) == EXIT_SUCCESS) then it's a normal exit, otherwise there
was an error or the program received a fatal signal). No idea how to
interpret the exit code on win32.

Alternatively, or in addition, you could just watch stderr for messages, and
assume that an error has occured if unzip prints a message to stderr.

Cheers
 -Tim

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Distinguish between G_IO_ERR and G_IO_HUP

Colossus
Tim Müller wrote:
> When the child exits, the callback function you passed to g_child_watch_add()
> is called with the exit status of the child, which will tell you if the child
> exited with an error or not. On unix, you'll need the macros described in the
> waitpid manpage to interpret the exit code (e.g. if (WIFEXITED(status) &&
> WEXITSTATUS(status) == EXIT_SUCCESS) then it's a normal exit, otherwise there
> was an error or the program received a fatal signal). No idea how to
> interpret the exit code on win32.

So I have to use g_child_watch_add() only or also with:
SetIOChannel (output_fd,
G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL,ZipOutput, NULL );

GIOChannel *SetIOChannel (gint fd, GIOCondition cond, GIOFunc func,
gpointer data)
{
        GIOChannel *ioc;
        /* set up handler for data */
        ioc = g_io_channel_unix_new(fd);
        g_io_add_watch (ioc, cond, func, data);
        return ioc;
}

Both of them or g_child_watch_add replaces g_io_add_watch ??
--
Colossus

Cpsed, a Linux OpenGL 3D scene editor
http://cpsed.sourceforge.net/

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list