#include "wx/intl.h"
#include "wx/log.h"
#include "wx/app.h"
+ #include "wx/wxcrtvararg.h"
#endif
#include "wx/apptrait.h"
#include "wx/unix/private.h"
#include <pwd.h>
+#include <sys/wait.h> // waitpid()
#ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
// get OS version
int major, minor;
wxString release = wxGetCommandOutput(wxT("uname -r"));
- if ( !release.empty() && wxSscanf(release, wxT("%d.%d"), &major, &minor) != 2 )
+ if ( release.empty() || wxSscanf(release, wxT("%d.%d"), &major, &minor) != 2 )
{
- // unrecognized uname string format
+ // failed to get version string or unrecognized format
major =
minor = -1;
}
}
+ if ( !(flags & wxEXEC_NOEVENTS) )
+ {
#if defined(__DARWIN__) && (defined(__WXMAC__) || defined(__WXCOCOA__))
- endProcData->tag = wxAddProcessCallbackForPid(endProcData, execData.pid);
+ endProcData->tag = wxAddProcessCallbackForPid(endProcData, execData.pid);
#else
- endProcData->tag = wxAddProcessCallback
- (
- endProcData,
- execData.pipeEndProcDetect.Detach(wxPipe::Read)
- );
+ endProcData->tag = wxAddProcessCallback
+ (
+ endProcData,
+ execData.pipeEndProcDetect.Detach(wxPipe::Read)
+ );
- execData.pipeEndProcDetect.Close();
+ execData.pipeEndProcDetect.Close();
#endif // defined(__DARWIN__) && (defined(__WXMAC__) || defined(__WXCOCOA__))
+ }
if ( flags & wxEXEC_SYNC )
{
wxBusyCursor bc;
- wxWindowDisabler *wd = flags & wxEXEC_NODISABLE ? NULL
- : new wxWindowDisabler;
+ int exitcode = 0;
+
+ wxWindowDisabler *wd = flags & (wxEXEC_NODISABLE | wxEXEC_NOEVENTS)
+ ? NULL
+ : new wxWindowDisabler;
- // endProcData->pid will be set to 0 from GTK_EndProcessDetector when the
- // process terminates
- while ( endProcData->pid != 0 )
+ if ( flags & wxEXEC_NOEVENTS )
{
- bool idle = true;
+ // just block waiting for the child to exit
+ int status = 0;
-#if HAS_PIPE_INPUT_STREAM
- if ( execData.bufOut )
+ int result = waitpid(execData.pid, &status, 0);
+
+ if ( result == -1 )
{
- execData.bufOut->Update();
- idle = false;
+ wxLogLastError(_T("waitpid"));
+ exitcode = -1;
}
-
- if ( execData.bufErr )
+ else
{
- execData.bufErr->Update();
- idle = false;
+ wxASSERT_MSG( result == execData.pid,
+ _T("unexpected waitpid() return value") );
+
+ if ( WIFEXITED(status) )
+ {
+ exitcode = WEXITSTATUS(status);
+ }
+ else // abnormal termination?
+ {
+ wxASSERT_MSG( WIFSIGNALED(status),
+ _T("unexpected child wait status") );
+ exitcode = -1;
+ }
}
+ }
+ else // !wxEXEC_NOEVENTS
+ {
+ // endProcData->pid will be set to 0 from GTK_EndProcessDetector when the
+ // process terminates
+ while ( endProcData->pid != 0 )
+ {
+ bool idle = true;
+
+#if HAS_PIPE_INPUT_STREAM
+ if ( execData.bufOut )
+ {
+ execData.bufOut->Update();
+ idle = false;
+ }
+
+ if ( execData.bufErr )
+ {
+ execData.bufErr->Update();
+ idle = false;
+ }
#endif // HAS_PIPE_INPUT_STREAM
- // don't consume 100% of the CPU while we're sitting in this
- // loop
- if ( idle )
- wxMilliSleep(1);
+ // don't consume 100% of the CPU while we're sitting in this
+ // loop
+ if ( idle )
+ wxMilliSleep(1);
- // give GTK+ a chance to call GTK_EndProcessDetector here and
- // also repaint the GUI
- wxYield();
- }
+ // give GTK+ a chance to call GTK_EndProcessDetector here and
+ // also repaint the GUI
+ wxYield();
+ }
- int exitcode = endProcData->exitcode;
+ exitcode = endProcData->exitcode;
+ }
delete wd;
delete endProcData;