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. */
81 WaitForSingleObject(pInfo.hProcess, INFINITE);
82 if (GetExitCodeProcess(pInfo.hProcess, &retCode) == 0) return -1;
84 CloseHandle(pInfo.hProcess);
85 CloseHandle(pInfo.hThread);
90 /* -------------------- UNIX VERSION --------------------- */
93 rawSystem(HsAddr cmd, HsAddr args)
98 switch(pid = fork()) {
105 #ifdef HAVE_SETITIMER
106 /* Reset the itimers in the child, so it doesn't get plagued
107 * by SIGVTALRM interrupts.
109 struct timeval tv_null = { 0, 0 };
110 struct itimerval itv;
111 itv.it_interval = tv_null;
112 itv.it_value = tv_null;
113 setitimer(ITIMER_REAL, &itv, NULL);
114 setitimer(ITIMER_VIRTUAL, &itv, NULL);
115 setitimer(ITIMER_PROF, &itv, NULL);
124 while (waitpid(pid, &wstat, 0) < 0) {
125 if (errno != EINTR) {
130 if (WIFEXITED(wstat))
131 return WEXITSTATUS(wstat);
132 else if (WIFSIGNALED(wstat)) {
136 /* This should never happen */