2 * (c) The University of Glasgow 1994-2004
4 * shell-less system Runtime Support (see System.Cmd.rawSystem).
7 /* The itimer stuff in this module is non-posix */
8 /* #include "PosixSource.h" */
10 /* This ifdef is required because this source might be compiled by an
11 * external compiler. See ghc/utils/runghc/rawSystem.c for example.
13 #ifdef __GLASGOW_HASKELL__
14 #if __GLASGOW_HASKELL__ < 603
17 #include "ghcconfig.h"
30 #ifdef HAVE_SYS_WAIT_H
34 # ifdef TIME_WITH_SYS_TIME
35 # include <sys/time.h>
38 # ifdef HAVE_SYS_TIME_H
39 # include <sys/time.h>
47 #if defined(mingw32_TARGET_OS)
59 #if defined(mingw32_TARGET_OS)
60 /* -------------------- WINDOWS VERSION --------------------- */
66 PROCESS_INFORMATION pInfo;
69 ZeroMemory(&sInfo, sizeof(sInfo));
70 sInfo.cb = sizeof(sInfo);
72 if (!CreateProcess(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &sInfo, &pInfo)) {
73 /* The 'TRUE' says that the created process should share
74 handles with the current process. This is vital to ensure
75 that error messages sent to stderr actually appear on the screen.
76 Since we are going to wait for the process to terminate anyway,
77 there is no problem with such sharing. */
79 errno = EINVAL; // ToDo: wrong, caller should use GetLastError()
82 WaitForSingleObject(pInfo.hProcess, INFINITE);
83 if (GetExitCodeProcess(pInfo.hProcess, &retCode) == 0) {
84 errno = EINVAL; // ToDo: wrong, caller should use GetLastError()
88 CloseHandle(pInfo.hProcess);
89 CloseHandle(pInfo.hThread);
94 /* -------------------- UNIX VERSION --------------------- */
97 rawSystem(HsAddr cmd, HsAddr args)
102 switch(pid = fork()) {
109 #ifdef HAVE_SETITIMER
110 /* Reset the itimers in the child, so it doesn't get plagued
111 * by SIGVTALRM interrupts.
113 struct timeval tv_null = { 0, 0 };
114 struct itimerval itv;
115 itv.it_interval = tv_null;
116 itv.it_value = tv_null;
117 setitimer(ITIMER_REAL, &itv, NULL);
118 setitimer(ITIMER_VIRTUAL, &itv, NULL);
119 setitimer(ITIMER_PROF, &itv, NULL);
128 while (waitpid(pid, &wstat, 0) < 0) {
129 if (errno != EINTR) {
134 if (WIFEXITED(wstat))
135 return WEXITSTATUS(wstat);
136 else if (WIFSIGNALED(wstat)) {
140 /* This should never happen */