From dbd25330c5a762ed22b1ca5deb8acd56da419fdf Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 1 Oct 2001 12:32:07 +0000 Subject: [PATCH] fix for running csh scripts using wxExecute() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11767 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/utilsgtk.cpp | 20 ++++++++++++++++---- src/gtk1/utilsgtk.cpp | 20 ++++++++++++++++---- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/gtk/utilsgtk.cpp b/src/gtk/utilsgtk.cpp index 611d02bf16..f1346abc17 100644 --- a/src/gtk/utilsgtk.cpp +++ b/src/gtk/utilsgtk.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: utils.cpp +// Name: src/gtk/utilsgtk.cpp // Purpose: // Author: Robert Roebling // Id: $Id$ @@ -21,6 +21,7 @@ #include #include #include +#include // for WNOHANG #include #include "glib.h" @@ -142,12 +143,23 @@ static void GTK_EndProcessDetector(gpointer data, gint source, GdkInputCondition WXUNUSED(condition) ) { wxEndProcessData *proc_data = (wxEndProcessData *)data; + + // has the process really terminated? unfortunately GDK (or GLib) seem to + // generate G_IO_HUP notification even when it simply tries to read from a + // closed fd and hasn't terminated at all + int pid = (proc_data->pid > 0) ? proc_data->pid : -(proc_data->pid); + if ( waitpid(pid, NULL, WNOHANG) == 0 ) + { + // no, it didn't exit yet, continue waiting + return; + } + + // child exited, end waiting close(source); + + // don't call us again! gdk_input_remove(proc_data->tag); - // This has to come after gdk_input_remove() or we will - // occasionally receive multiple callbacks with corrupt data - // pointers. (KB) wxHandleProcessTermination(proc_data); } diff --git a/src/gtk1/utilsgtk.cpp b/src/gtk1/utilsgtk.cpp index 611d02bf16..f1346abc17 100644 --- a/src/gtk1/utilsgtk.cpp +++ b/src/gtk1/utilsgtk.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: utils.cpp +// Name: src/gtk/utilsgtk.cpp // Purpose: // Author: Robert Roebling // Id: $Id$ @@ -21,6 +21,7 @@ #include #include #include +#include // for WNOHANG #include #include "glib.h" @@ -142,12 +143,23 @@ static void GTK_EndProcessDetector(gpointer data, gint source, GdkInputCondition WXUNUSED(condition) ) { wxEndProcessData *proc_data = (wxEndProcessData *)data; + + // has the process really terminated? unfortunately GDK (or GLib) seem to + // generate G_IO_HUP notification even when it simply tries to read from a + // closed fd and hasn't terminated at all + int pid = (proc_data->pid > 0) ? proc_data->pid : -(proc_data->pid); + if ( waitpid(pid, NULL, WNOHANG) == 0 ) + { + // no, it didn't exit yet, continue waiting + return; + } + + // child exited, end waiting close(source); + + // don't call us again! gdk_input_remove(proc_data->tag); - // This has to come after gdk_input_remove() or we will - // occasionally receive multiple callbacks with corrupt data - // pointers. (KB) wxHandleProcessTermination(proc_data); } -- 2.45.2