X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9f2d09aad264fd6d2b9731aad440b97bd8e24e75..b704229ee25ef8e5765ec09e9c164f59063564e8:/src/unix/utilsunx.cpp diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index 018bf84ca2..2082e6bca1 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -23,6 +23,7 @@ #include "wx/utils.h" #include "wx/process.h" +#include "wx/thread.h" #include "wx/unix/execute.h" @@ -44,7 +45,7 @@ // JACS: needed for FD_SETSIZE #include -#if HAVE_UNAME +#ifdef HAVE_UNAME #include // for uname() #endif // HAVE_UNAME @@ -64,20 +65,21 @@ #ifdef __SUN__ int usleep(unsigned int usec); #else // !Sun - #ifdef __EMX__ - /* I copied this from the XFree86 diffs. AV. */ - #define INCL_DOSPROCESS - #include - void usleep(unsigned long delay) - { - DosSleep(delay ? (delay/1000l) : 1l); - } - #else - void usleep(unsigned long usec); - #endif + #ifdef __EMX__ + /* I copied this from the XFree86 diffs. AV. */ + #define INCL_DOSPROCESS + #include + inline void usleep(unsigned long delay) + { + DosSleep(delay ? (delay/1000l) : 1l); + } + #else // !Sun && !EMX + void usleep(unsigned long usec); + #endif #endif // Sun/EMX/Something else }; -#define HAVE_USLEEP 1 + + #define HAVE_USLEEP 1 #endif // Unices without usleep() // ============================================================================ @@ -95,14 +97,14 @@ void wxSleep(int nSecs) void wxUsleep(unsigned long milliseconds) { -#if HAVE_NANOSLEEP +#ifdef HAVE_NANOSLEEP timespec tmReq; tmReq.tv_sec = milliseconds / 1000; tmReq.tv_nsec = (milliseconds % 1000) * 1000 * 1000; // we're not interested in remaining time nor in return value (void)nanosleep(&tmReq, (timespec *)NULL); -#elif HAVE_USLEEP +#elif defined( HAVE_USLEEP ) // uncomment this if you feel brave or if you are sure that your version // of Solaris has a safe usleep() function but please notice that usleep() // is known to lead to crashes in MT programs in Solaris 2.[67] and is not @@ -217,9 +219,24 @@ 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; + + // wait for child termination and if waitpid() was interrupted, try again + do { - wxLogSysError(_("Waiting for subprocess termination failed")); + rc = waitpid(pid, &status, 0); + } + while ( rc == -1 && errno == EINTR ); + + + if( rc == -1 || ! (WIFEXITED(status) || WIFSIGNALED(status)) ) + { + wxLogSysError(_("Waiting for subprocess termination failed")); + /* AFAIK, this can only happen if something went wrong within + wxGTK, i.e. due to a race condition or some serious bug. + After having fixed the order of statements in + GTK_EndProcessDetector(). (KB) + */ } else { @@ -229,19 +246,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; + // clean up + if ( proc_data->pid > 0 ) + { + delete proc_data; + } + else + { + // wxExecute() will know about it + proc_data->exitcode = status; - proc_data->pid = 0; + proc_data->pid = 0; + } } } @@ -286,7 +302,7 @@ long wxExecute( wxChar **argv, bool sync, wxProcess *process ) #endif // wxUSE_GUI // fork the process -#if HAVE_VFORK +#ifdef HAVE_VFORK pid_t pid = vfork(); #else pid_t pid = fork(); @@ -345,11 +361,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 +373,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 +390,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; } @@ -393,6 +412,7 @@ long wxExecute( wxChar **argv, bool sync, wxProcess *process ) return exitcode; #endif // wxUSE_GUI } + return 0; #undef ARGS_CLEANUP } @@ -550,16 +570,29 @@ bool wxGetUserName(wxChar *buf, int sz) *buf = wxT('\0'); if ((who = getpwuid (getuid ())) != NULL) { +#ifndef __VMS__ comma = strchr(who->pw_gecos, ','); if (comma) *comma = '\0'; // cut off non-name comment fields wxStrncpy (buf, wxConvertMB2WX(who->pw_gecos), sz - 1); +#else + wxStrncpy (buf, wxConvertMB2WX(who->pw_name), sz - 1); +#endif return TRUE; } return FALSE; } +wxString wxGetOsDescription() +{ +#ifndef WXWIN_OS_DESCRIPTION + #error WXWIN_OS_DESCRIPTION should be defined in config.h by configure +#else + return WXWIN_OS_DESCRIPTION; +#endif +} + // ---------------------------------------------------------------------------- // error and debug output routines (deprecated, use wxLog) // ----------------------------------------------------------------------------