X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/55acd85e7134f8d16d40dc21cd665c5ea18a98f1..169935ad4ed842421ef24470a06d1aa298f90fbe:/src/motif/utilsexc.cpp diff --git a/src/motif/utilsexc.cpp b/src/motif/utilsexc.cpp index 94ff593d4f..ed134bd874 100644 --- a/src/motif/utilsexc.cpp +++ b/src/motif/utilsexc.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #ifdef VMS /*steve*/ @@ -35,11 +36,11 @@ #else -#if defined(_AIX) || defined(__xlC__) +#if defined(__AIX__) || defined(__xlC__) #include #include #else -#ifndef DG +#ifndef __DATA_GENERAL__ #include #endif #endif @@ -51,112 +52,166 @@ #endif +#ifdef __SVR4__ +#include +#endif + +#ifdef __SOLARIS__ +// somehow missing from sys/wait.h but in the system's docs +extern "C" +{ + pid_t wait4(pid_t pid, int *statusp, int options, struct rusage + *rusage); +} +#endif + #include +#include #include -#define wxEXECUTE_WIN_MESSAGE 10000 +struct wxLocalProcessData +{ + int pid, end_process; + wxProcess *process; +}; -void xt_notify_end_process(XtPointer client, int *fid, - XtInputId *id) +#ifdef __SOLARIS__ +// somehow missing from sys/wait.h but in the system's docs +extern "C" { - Bool *flag = (Bool *) client; - *flag = TRUE; + pid_t wait4(pid_t pid, int *statusp, int options, struct rusage + *rusage); +} +#endif - XtRemoveInput(*id); +void xt_notify_end_process(XtPointer client, int *fid, + XtInputId *id) +{ + wxLocalProcessData *process_data = (wxLocalProcessData *)client; + + int pid; + + pid = (process_data->pid > 0) ? process_data->pid : -(process_data->pid); + + /* wait4 is not part of any standard, use at own risk + * not sure what wait4 does, but wait3 seems to be closest, whats a digit ;-) + * --- offer@sgi.com */ +#if !defined(__sgi) && !defined(__SGI__) && !defined(__ALPHA__) && !defined(__SUNCC__) + wait4(process_data->pid, NULL, 0, NULL); +#else + wait3((int *) NULL, 0, (rusage *) NULL); +#endif + + XtRemoveInput(*id); + if (process_data->process) + process_data->process->OnTerminate(process_data->pid); + + process_data->end_process = TRUE; + + if (process_data->pid > 0) + delete process_data; + else + process_data->pid = 0; } -long wxExecute(char **argv, bool sync, wxProcess *WXUNUSED(handler)) +long wxExecute(char **argv, bool sync, wxProcess *handler) { #ifdef VMS - return(0); + return(0); #else - if (*argv == NULL) - return 0; // Nothing??? - - int proc_link[2]; - if (pipe(proc_link)) - return 0; - - /* fork the process */ + if (*argv == NULL) + return 0; // Nothing??? + + int proc_link[2]; + if (pipe(proc_link)) + return 0; + + /* fork the process */ #if defined(sun) || defined(__ultrix) || defined(__bsdi__) - pid_t pid = vfork (); + pid_t pid = vfork (); #else - pid_t pid = fork (); + pid_t pid = fork (); #endif - - if (pid == -1) + + if (pid == -1) { - return 0; + return 0; } - else if (pid == 0) + else if (pid == 0) { -/* GUILHEM: Close all fds when sync == 0 */ - if (sync == 0) - for (int fd=0;fdGetAppContext(), proc_link[0], - (XtPointer *) XtInputReadMask, - (XtInputCallbackProc) xt_notify_end_process, - (XtPointer) &end_process); - - if (sync) { - while (!end_process) - XtAppProcessEvent((XtAppContext) wxTheApp->GetAppContext(), XtIMAll); - - if (WIFEXITED(end_process) != 0) - return WEXITSTATUS(end_process); - } - - return pid; + + wxLocalProcessData *process_data = new wxLocalProcessData; + + process_data->end_process = 0; + process_data->process = handler; + process_data->pid = (sync) ? pid : -pid; + + close(proc_link[1]); + XtAppAddInput((XtAppContext) wxTheApp->GetAppContext(), proc_link[0], + (XtPointer *) XtInputReadMask, + (XtInputCallbackProc) xt_notify_end_process, + (XtPointer) process_data); + + if (sync) { + while (!process_data->end_process) + XtAppProcessEvent((XtAppContext) wxTheApp->GetAppContext(), XtIMAll); + + if (WIFEXITED(process_data->end_process) != 0) + return WEXITSTATUS(process_data->end_process); + } + + delete process_data; + + return pid; #endif - // end VMS + // end VMS } -long wxExecute (const wxString& command, bool sync, wxProcess* WXUNUSED(process)) +long wxExecute (const wxString& command, bool sync, wxProcess* handler) { #ifdef VMS - return(0); + return(0); #else - if (command.IsNull() || command == "") - return 0; // Nothing to do - - // Run a program the recomended way under X (XView) - int argc = 0; - char *argv[127]; - char tmp[1024]; - const char *IFS = " \t\n"; - - // Build argument vector - strncpy (tmp, (const char*) command, sizeof (tmp) / sizeof (char) - 1); - tmp[sizeof (tmp) / sizeof (char) - 1] = '\0'; - argv[argc++] = strtok (tmp, IFS); - while ((argv[argc++] = strtok (NULL, IFS)) != NULL) - /* loop */ ; - - return wxExecute(argv, sync); + if (command.IsNull() || command == "") + return 0; // Nothing to do + + // Run a program the recomended way under X (XView) + int argc = 0; + char *argv[127]; + char tmp[1024]; + const char *IFS = " \t\n"; + + // Build argument vector + strncpy (tmp, (const char*) command, sizeof (tmp) / sizeof (char) - 1); + tmp[sizeof (tmp) / sizeof (char) - 1] = '\0'; + argv[argc++] = strtok (tmp, IFS); + while ((argv[argc++] = strtok (NULL, IFS)) != NULL) + /* loop */ ; + + return wxExecute(argv, sync, handler); #endif - // VMS + // VMS }