From: Karsten Ballüder Date: Wed, 1 Dec 1999 18:16:53 +0000 (+0000) Subject: fixed process termination handling X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/ab857a4ed6687929e308ea606f65ceedc43d1319 fixed process termination handling git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4789 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/gtk/utilsgtk.cpp b/src/gtk/utilsgtk.cpp index 963e7b5991..e1c9989495 100644 --- a/src/gtk/utilsgtk.cpp +++ b/src/gtk/utilsgtk.cpp @@ -110,12 +110,14 @@ int wxGetOsVersion(int *majorVsn, int *minorVsn) static void GTK_EndProcessDetector(gpointer data, gint source, GdkInputCondition WXUNUSED(condition) ) { - wxEndProcessData *proc_data = (wxEndProcessData *)data; - - wxHandleProcessTermination(proc_data); - - close(source); - gdk_input_remove(proc_data->tag); + wxEndProcessData *proc_data = (wxEndProcessData *)data; + close(source); + gdk_input_remove(proc_data->tag); + + // This has to come after gdk_input_remove() or we will + // occasionally receive multiple callbacks with corrupt data + // pointers. (KB) + wxHandleProcessTermination(proc_data); } int wxAddProcessCallback(wxEndProcessData *proc_data, int fd) diff --git a/src/gtk1/utilsgtk.cpp b/src/gtk1/utilsgtk.cpp index 963e7b5991..e1c9989495 100644 --- a/src/gtk1/utilsgtk.cpp +++ b/src/gtk1/utilsgtk.cpp @@ -110,12 +110,14 @@ int wxGetOsVersion(int *majorVsn, int *minorVsn) static void GTK_EndProcessDetector(gpointer data, gint source, GdkInputCondition WXUNUSED(condition) ) { - wxEndProcessData *proc_data = (wxEndProcessData *)data; - - wxHandleProcessTermination(proc_data); - - close(source); - gdk_input_remove(proc_data->tag); + wxEndProcessData *proc_data = (wxEndProcessData *)data; + close(source); + gdk_input_remove(proc_data->tag); + + // This has to come after gdk_input_remove() or we will + // occasionally receive multiple callbacks with corrupt data + // pointers. (KB) + wxHandleProcessTermination(proc_data); } int wxAddProcessCallback(wxEndProcessData *proc_data, int fd) diff --git a/src/unix/dialup.cpp b/src/unix/dialup.cpp index e0616d2305..f6023963be 100644 --- a/src/unix/dialup.cpp +++ b/src/unix/dialup.cpp @@ -383,6 +383,13 @@ wxDialUpManagerImpl::DisableAutoCheckOnlineStatus() void wxDialUpManagerImpl::SetWellKnownHost(const wxString& hostname, int portno) { + if(hostname.Length() == 0) + { + m_BeaconHost = WXDIALUP_MANAGER_DEFAULT_BEACONHOST; + m_BeaconPort = 80; + return; + } + /// does hostname contain a port number? wxString port = hostname.After(wxT(':')); if(port.Length()) diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index 0b2e074026..c8bdafd3bf 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -217,9 +217,22 @@ void wxHandleProcessTermination(wxEndProcessData *proc_data) // systems wait() might be used instead in a loop (until the right pid // terminates) int status = 0; - if ( waitpid(pid, &status, 0) == -1 || !WIFEXITED(status) ) + int rc; + + do + rc = waitpid(pid, &status, 0); + while(rc == -1 && ( /* errno == ERESTARTSYS || */ errno == EINTR) ); + // waitpid() was interrupted, try again + + + if( rc == -1 || ! (WIFEXITED(status) || WIFSIGNALED(status)) ) { - wxLogSysError(_("Waiting for subprocess termination failed")); + wxLogSysError(_("Waiting for subprocess termination failed")); + /* AFAIK, this can only happen if something went wrong within + wxGTK, i.e. due to a racecondition or some serious bug. + After having fixed the order of statements in + GTK_EndProcessDetector(). (KB) + */ } else { @@ -229,19 +242,18 @@ void wxHandleProcessTermination(wxEndProcessData *proc_data) proc_data->process->OnTerminate(proc_data->pid, WEXITSTATUS(status)); } - } - - // clean up - if ( proc_data->pid > 0 ) - { - delete proc_data; - } - else - { - // wxExecute() will know about it - proc_data->exitcode = status; - - proc_data->pid = 0; + // clean up + if ( proc_data->pid > 0 ) + { + delete proc_data; + } + else + { + // wxExecute() will know about it + proc_data->exitcode = status; + + proc_data->pid = 0; + } } } @@ -345,11 +357,8 @@ long wxExecute( wxChar **argv, bool sync, wxProcess *process ) else { #if wxUSE_GUI - // we're in parent - close(end_proc_detect[1]); // close writing side - wxEndProcessData *data = new wxEndProcessData; - data->tag = wxAddProcessCallback(data, end_proc_detect[0]); + ARGS_CLEANUP; @@ -360,6 +369,9 @@ long wxExecute( wxChar **argv, bool sync, wxProcess *process ) // sync execution: indicate it by negating the pid data->pid = -pid; + data->tag = wxAddProcessCallback(data, end_proc_detect[0]); + // we're in parent + close(end_proc_detect[1]); // close writing side // it will be set to 0 from GTK_EndProcessDetector while (data->pid != 0) @@ -374,10 +386,13 @@ long wxExecute( wxChar **argv, bool sync, wxProcess *process ) else { // async execution, nothing special to do - caller will be - // notified about the process terminationif process != NULL, data + // notified about the process termination if process != NULL, data // will be deleted in GTK_EndProcessDetector data->process = process; data->pid = pid; + data->tag = wxAddProcessCallback(data, end_proc_detect[0]); + // we're in parent + close(end_proc_detect[1]); // close writing side return pid; }