From 3fee3116ddb5c4ce3bd87731b92b1c6d22b4ae15 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 2 Nov 2010 11:57:24 +0000 Subject: [PATCH] Make write end of the child process pipe non-blocking under Unix. 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 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index fa2eb47287..fa5ee5d7b7 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -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)); -- 2.47.2