2 * (c) The University of Glasgow 1994-2003
4 * shell-less system Runtime Support (see System.Cmd.rawSystem).
7 /* The itimer stuff in this module is non-posix */
8 /* #include "PosixSource.h" */
21 #ifdef HAVE_SYS_WAIT_H
25 # ifdef TIME_WITH_SYS_TIME
26 # include <sys/time.h>
29 # ifdef HAVE_SYS_TIME_H
30 # include <sys/time.h>
38 #if defined(mingw32_TARGET_OS)
50 #if defined(mingw32_TARGET_OS)
51 /* -------------------- WINDOWS VERSION --------------------- */
57 PROCESS_INFORMATION pInfo;
60 sInfo.cb = sizeof(STARTUPINFO);
61 sInfo.lpReserved = NULL;
62 sInfo.lpReserved2 = NULL;
63 sInfo.cbReserved2 = 0;
64 sInfo.lpDesktop = NULL;
68 if (!CreateProcess(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &sInfo, &pInfo))
69 /* The 'TRUE' says that the created process should share
70 handles with the current process. This is vital to ensure
71 that error messages sent to stderr actually appear on the screen.
72 Since we are going to wait for the process to terminate anyway,
73 there is no problem with such sharing. */
76 WaitForSingleObject(pInfo.hProcess, INFINITE);
77 if (GetExitCodeProcess(pInfo.hProcess, &retCode) == 0) return -1;
78 CloseHandle(pInfo.hProcess);
79 CloseHandle(pInfo.hThread);
84 /* -------------------- UNIX VERSION --------------------- */
87 rawSystem(HsAddr cmd, HsAddr args)
92 switch(pid = fork()) {
100 /* Reset the itimers in the child, so it doesn't get plagued
101 * by SIGVTALRM interrupts.
103 struct timeval tv_null = { 0, 0 };
104 struct itimerval itv;
105 itv.it_interval = tv_null;
106 itv.it_value = tv_null;
107 setitimer(ITIMER_REAL, &itv, NULL);
108 setitimer(ITIMER_VIRTUAL, &itv, NULL);
109 setitimer(ITIMER_PROF, &itv, NULL);
118 while (waitpid(pid, &wstat, 0) < 0) {
119 if (errno != EINTR) {
124 if (WIFEXITED(wstat))
125 return WEXITSTATUS(wstat);
126 else if (WIFSIGNALED(wstat)) {
130 /* This should never happen */