+ // loop while we're getting EINTR
+ for ( ;; )
+ {
+ rc = waitpid(pid, &status, flags);
+
+ if ( rc != -1 || errno != EINTR )
+ break;
+ }
+
+ if ( rc == 0 )
+ {
+ // This can only happen if the child application closes our dummy pipe
+ // that is used to monitor its lifetime; in that case, our best bet is
+ // to pretend the process did terminate, because otherwise wxExecute()
+ // would hang indefinitely (OnReadWaiting() won't be called again, the
+ // descriptor is closed now).
+ wxLogDebug("Child process (PID %d) still alive but pipe closed so "
+ "generating a close notification", pid);
+ }
+ else if ( rc == -1 )
+ {
+ wxLogLastError(wxString::Format("waitpid(%d)", pid));
+ }
+ else // child did terminate
+ {
+ wxASSERT_MSG( rc == pid, "unexpected waitpid() return value" );
+
+ // notice that the caller expects the exit code to be signed, e.g. -1
+ // instead of 255 so don't assign WEXITSTATUS() to an int
+ signed char exitcode;
+ if ( WIFEXITED(status) )
+ exitcode = WEXITSTATUS(status);
+ else if ( WIFSIGNALED(status) )
+ exitcode = -WTERMSIG(status);
+ else
+ {
+ wxLogError("Child process (PID %d) exited for unknown reason, "
+ "status = %d", pid, status);
+ exitcode = -1;
+ }