]> git.saurik.com Git - wxWidgets.git/commitdiff
Make write end of the child process pipe non-blocking under Unix.
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 2 Nov 2010 11:57:24 +0000 (11:57 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 2 Nov 2010 11:57:24 +0000 (11:57 +0000)
We need to make at least one end of the pipe used to communicate with
wxExecute() child process non-blocking to avoid deadlocks, so unblock the
write end of the pipe. It seems to be unnecessary to unblock the reading ends
of std{out,err} pipes as we can already check for the presence of input there.
This is also consistent with wxMSW behaviour.

Closes #12636.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65993 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/unix/utilsunx.cpp

index fa2eb472873f9e724f9ec3e3eccc1461f1b08166..fa5ee5d7b7ce8d240b8a9f6b83d86431f55e267d 100644 (file)
@@ -651,6 +651,19 @@ long wxExecute(char **argv, int flags, wxProcess *process,
 
         if ( process && process->IsRedirected() )
         {
+            // Avoid deadlocks which could result from trying to write to the
+            // child input pipe end while the child itself is writing to its
+            // output end and waiting for us to read from it.
+            if ( !pipeIn.MakeNonBlocking(wxPipe::Write) )
+            {
+                // This message is not terrible useful for the user but what
+                // else can we do? Also, should we fail here or take the risk
+                // to continue and deadlock? Currently we choose the latter but
+                // it might not be the best idea.
+                wxLogSysError(_("Failed to set up non-blocking pipe, "
+                                "the program might hang."));
+            }
+
             wxOutputStream *inStream =
                 new wxFileOutputStream(pipeIn.Detach(wxPipe::Write));