]> git.saurik.com Git - wxWidgets.git/commitdiff
fix for running csh scripts using wxExecute()
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 1 Oct 2001 12:32:07 +0000 (12:32 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 1 Oct 2001 12:32:07 +0000 (12:32 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11767 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/gtk/utilsgtk.cpp
src/gtk1/utilsgtk.cpp

index 611d02bf16f5a8cad5fcddadcccd6b4a69d55f1e..f1346abc17b2edef3668b446a1ac2a23fde3f5e5 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        utils.cpp
+// Name:        src/gtk/utilsgtk.cpp
 // Purpose:
 // Author:      Robert Roebling
 // Id:          $Id$
@@ -21,6 +21,7 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <sys/wait.h>   // for WNOHANG
 #include <unistd.h>
 
 #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);
 }
 
index 611d02bf16f5a8cad5fcddadcccd6b4a69d55f1e..f1346abc17b2edef3668b446a1ac2a23fde3f5e5 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        utils.cpp
+// Name:        src/gtk/utilsgtk.cpp
 // Purpose:
 // Author:      Robert Roebling
 // Id:          $Id$
@@ -21,6 +21,7 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <sys/wait.h>   // for WNOHANG
 #include <unistd.h>
 
 #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);
 }