]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk1/utilsgtk.cpp
cleaned up the checkbox creation code (~70 lines of code became 3)
[wxWidgets.git] / src / gtk1 / utilsgtk.cpp
index 611d02bf16f5a8cad5fcddadcccd6b4a69d55f1e..1bc1106f93e420c45945d76e6a8c140b809139cd 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
-// Name:        utils.cpp
+// Name:        src/gtk/utilsgtk.cpp
 // Purpose:
 // Author:      Robert Roebling
 // Id:          $Id$
 // Purpose:
 // Author:      Robert Roebling
 // Id:          $Id$
@@ -21,6 +21,7 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <sys/wait.h>   // for WNOHANG
 #include <unistd.h>
 
 #include "glib.h"
 #include <unistd.h>
 
 #include "glib.h"
@@ -138,16 +139,35 @@ wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
 // subprocess routines
 // ----------------------------------------------------------------------------
 
 // subprocess routines
 // ----------------------------------------------------------------------------
 
-static void GTK_EndProcessDetector(gpointer data, gint source,
-                                   GdkInputCondition WXUNUSED(condition) )
+extern "C"
+void GTK_EndProcessDetector(gpointer data, gint source,
+                            GdkInputCondition WXUNUSED(condition) )
 {
    wxEndProcessData *proc_data = (wxEndProcessData *)data;
 {
    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);
+   int status = 0;
+   int rc = waitpid(pid, &status, WNOHANG);
+
+   if ( rc == 0 )
+   {
+       // no, it didn't exit yet, continue waiting
+       return;
+   }
+
+   // set exit code to -1 if something bad happened
+   proc_data->exitcode = rc != -1 && WIFEXITED(status) ? WEXITSTATUS(status)
+                                                      : -1;
+
+   // child exited, end waiting
    close(source);
    close(source);
+
+   // don't call us again!
    gdk_input_remove(proc_data->tag);
 
    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);
 }
 
    wxHandleProcessTermination(proc_data);
 }