]> git.saurik.com Git - wxWidgets.git/commitdiff
fixed the exit code detection for async processes
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 2 Oct 2001 19:22:24 +0000 (19:22 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 2 Oct 2001 19:22:24 +0000 (19:22 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11787 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/gtk/utilsgtk.cpp
src/gtk1/utilsgtk.cpp
src/unix/utilsunx.cpp

index f1346abc17b2edef3668b446a1ac2a23fde3f5e5..1296a0f7624cf22a7ceae8a9546d8464f27ceffd 100644 (file)
@@ -148,12 +148,19 @@ static void GTK_EndProcessDetector(gpointer data, gint source,
    // 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 )
+   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);
 
index f1346abc17b2edef3668b446a1ac2a23fde3f5e5..1296a0f7624cf22a7ceae8a9546d8464f27ceffd 100644 (file)
@@ -148,12 +148,19 @@ static void GTK_EndProcessDetector(gpointer data, gint source,
    // 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 )
+   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);
 
index fbf5377f76fb6e7412f15e56ac7ab1e9a0bf1cc5..0581126a283e06b858fb6242053c1c8603a9cdd8 100644 (file)
@@ -288,32 +288,12 @@ bool wxShell(const wxString& command, wxArrayString& output)
 
 void wxHandleProcessTermination(wxEndProcessData *proc_data)
 {
-    int pid = (proc_data->pid > 0) ? proc_data->pid : -(proc_data->pid);
-
-    // waitpid is POSIX so should be available everywhere, however on older
-    // systems wait() might be used instead in a loop (until the right pid
-    // terminates)
-    int status = 0;
-    int rc;
-
-    // wait for child termination and if waitpid() was interrupted, try again
-    do
-    {
-       rc = waitpid(pid, &status, 0);
-    }
-    while ( rc == -1 && errno == EINTR );
-
     // notify user about termination if required
     if ( proc_data->process )
     {
-        proc_data->process->OnTerminate
-                            (
-                                proc_data->pid,
-                                (rc == 0) && WIFEXITED(status)
-                                    ? WEXITSTATUS(status)
-                                    : -1
-                            );
+        proc_data->process->OnTerminate(proc_data->pid, proc_data->exitcode);
     }
+
     // clean up
     if ( proc_data->pid > 0 )
     {
@@ -321,9 +301,7 @@ void wxHandleProcessTermination(wxEndProcessData *proc_data)
     }
     else
     {
-       // wxExecute() will know about it
-       proc_data->exitcode = status;
-
+       // let wxExecute() know that the process has terminated
        proc_data->pid = 0;
     }
 }