fixed process termination handling

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4789 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Karsten Ballüder
1999-12-01 18:16:53 +00:00
parent 371ee4026e
commit ab857a4ed6
4 changed files with 56 additions and 30 deletions

View File

@@ -111,11 +111,13 @@ static void GTK_EndProcessDetector(gpointer data, gint source,
GdkInputCondition WXUNUSED(condition) ) GdkInputCondition WXUNUSED(condition) )
{ {
wxEndProcessData *proc_data = (wxEndProcessData *)data; wxEndProcessData *proc_data = (wxEndProcessData *)data;
wxHandleProcessTermination(proc_data);
close(source); close(source);
gdk_input_remove(proc_data->tag); 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) int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)

View File

@@ -111,11 +111,13 @@ static void GTK_EndProcessDetector(gpointer data, gint source,
GdkInputCondition WXUNUSED(condition) ) GdkInputCondition WXUNUSED(condition) )
{ {
wxEndProcessData *proc_data = (wxEndProcessData *)data; wxEndProcessData *proc_data = (wxEndProcessData *)data;
wxHandleProcessTermination(proc_data);
close(source); close(source);
gdk_input_remove(proc_data->tag); 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) int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)

View File

@@ -383,6 +383,13 @@ wxDialUpManagerImpl::DisableAutoCheckOnlineStatus()
void void
wxDialUpManagerImpl::SetWellKnownHost(const wxString& hostname, int portno) 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? /// does hostname contain a port number?
wxString port = hostname.After(wxT(':')); wxString port = hostname.After(wxT(':'));
if(port.Length()) if(port.Length())

View File

@@ -217,9 +217,22 @@ void wxHandleProcessTermination(wxEndProcessData *proc_data)
// systems wait() might be used instead in a loop (until the right pid // systems wait() might be used instead in a loop (until the right pid
// terminates) // terminates)
int status = 0; 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 else
{ {
@@ -229,8 +242,6 @@ void wxHandleProcessTermination(wxEndProcessData *proc_data)
proc_data->process->OnTerminate(proc_data->pid, proc_data->process->OnTerminate(proc_data->pid,
WEXITSTATUS(status)); WEXITSTATUS(status));
} }
}
// clean up // clean up
if ( proc_data->pid > 0 ) if ( proc_data->pid > 0 )
{ {
@@ -244,6 +255,7 @@ void wxHandleProcessTermination(wxEndProcessData *proc_data)
proc_data->pid = 0; proc_data->pid = 0;
} }
} }
}
long wxExecute( wxChar **argv, bool sync, wxProcess *process ) long wxExecute( wxChar **argv, bool sync, wxProcess *process )
{ {
@@ -345,11 +357,8 @@ long wxExecute( wxChar **argv, bool sync, wxProcess *process )
else else
{ {
#if wxUSE_GUI #if wxUSE_GUI
// we're in parent
close(end_proc_detect[1]); // close writing side
wxEndProcessData *data = new wxEndProcessData; wxEndProcessData *data = new wxEndProcessData;
data->tag = wxAddProcessCallback(data, end_proc_detect[0]);
ARGS_CLEANUP; ARGS_CLEANUP;
@@ -360,6 +369,9 @@ long wxExecute( wxChar **argv, bool sync, wxProcess *process )
// sync execution: indicate it by negating the pid // sync execution: indicate it by negating the pid
data->pid = -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 // it will be set to 0 from GTK_EndProcessDetector
while (data->pid != 0) while (data->pid != 0)
@@ -378,6 +390,9 @@ long wxExecute( wxChar **argv, bool sync, wxProcess *process )
// will be deleted in GTK_EndProcessDetector // will be deleted in GTK_EndProcessDetector
data->process = process; data->process = process;
data->pid = pid; 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; return pid;
} }