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:
@@ -110,12 +110,14 @@ int wxGetOsVersion(int *majorVsn, int *minorVsn)
|
|||||||
static void GTK_EndProcessDetector(gpointer data, gint source,
|
static void GTK_EndProcessDetector(gpointer data, gint source,
|
||||||
GdkInputCondition WXUNUSED(condition) )
|
GdkInputCondition WXUNUSED(condition) )
|
||||||
{
|
{
|
||||||
wxEndProcessData *proc_data = (wxEndProcessData *)data;
|
wxEndProcessData *proc_data = (wxEndProcessData *)data;
|
||||||
|
close(source);
|
||||||
|
gdk_input_remove(proc_data->tag);
|
||||||
|
|
||||||
wxHandleProcessTermination(proc_data);
|
// This has to come after gdk_input_remove() or we will
|
||||||
|
// occasionally receive multiple callbacks with corrupt data
|
||||||
close(source);
|
// pointers. (KB)
|
||||||
gdk_input_remove(proc_data->tag);
|
wxHandleProcessTermination(proc_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
|
int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
|
||||||
|
@@ -110,12 +110,14 @@ int wxGetOsVersion(int *majorVsn, int *minorVsn)
|
|||||||
static void GTK_EndProcessDetector(gpointer data, gint source,
|
static void GTK_EndProcessDetector(gpointer data, gint source,
|
||||||
GdkInputCondition WXUNUSED(condition) )
|
GdkInputCondition WXUNUSED(condition) )
|
||||||
{
|
{
|
||||||
wxEndProcessData *proc_data = (wxEndProcessData *)data;
|
wxEndProcessData *proc_data = (wxEndProcessData *)data;
|
||||||
|
close(source);
|
||||||
|
gdk_input_remove(proc_data->tag);
|
||||||
|
|
||||||
wxHandleProcessTermination(proc_data);
|
// This has to come after gdk_input_remove() or we will
|
||||||
|
// occasionally receive multiple callbacks with corrupt data
|
||||||
close(source);
|
// pointers. (KB)
|
||||||
gdk_input_remove(proc_data->tag);
|
wxHandleProcessTermination(proc_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
|
int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
|
||||||
|
@@ -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())
|
||||||
|
@@ -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,19 +242,18 @@ 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
|
||||||
|
if ( proc_data->pid > 0 )
|
||||||
|
{
|
||||||
|
delete proc_data;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// wxExecute() will know about it
|
||||||
|
proc_data->exitcode = status;
|
||||||
|
|
||||||
// clean up
|
proc_data->pid = 0;
|
||||||
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
|
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)
|
||||||
@@ -374,10 +386,13 @@ long wxExecute( wxChar **argv, bool sync, wxProcess *process )
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// async execution, nothing special to do - caller will be
|
// 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
|
// 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;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user