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 ZeroMemory(&sInfo, sizeof(sInfo));
61 sInfo.cb = sizeof(sInfo);
63 if (!CreateProcess(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &sInfo, &pInfo)) {
64 /* The 'TRUE' says that the created process should share
65 handles with the current process. This is vital to ensure
66 that error messages sent to stderr actually appear on the screen.
67 Since we are going to wait for the process to terminate anyway,
68 there is no problem with such sharing. */
72 WaitForSingleObject(pInfo.hProcess, INFINITE);
73 if (GetExitCodeProcess(pInfo.hProcess, &retCode) == 0) return -1;
75 CloseHandle(pInfo.hProcess);
76 CloseHandle(pInfo.hThread);
81 /* -------------------- UNIX VERSION --------------------- */
84 rawSystem(HsAddr cmd, HsAddr args)
89 switch(pid = fork()) {
97 /* Reset the itimers in the child, so it doesn't get plagued
98 * by SIGVTALRM interrupts.
100 struct timeval tv_null = { 0, 0 };
101 struct itimerval itv;
102 itv.it_interval = tv_null;
103 itv.it_value = tv_null;
104 setitimer(ITIMER_REAL, &itv, NULL);
105 setitimer(ITIMER_VIRTUAL, &itv, NULL);
106 setitimer(ITIMER_PROF, &itv, NULL);
115 while (waitpid(pid, &wstat, 0) < 0) {
116 if (errno != EINTR) {
121 if (WIFEXITED(wstat))
122 return WEXITSTATUS(wstat);
123 else if (WIFSIGNALED(wstat)) {
127 /* This should never happen */