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 #if __GLASGOW_HASKELL__ < 603
16 #include "ghcconfig.h"
28 #ifdef HAVE_SYS_WAIT_H
32 # ifdef TIME_WITH_SYS_TIME
33 # include <sys/time.h>
36 # ifdef HAVE_SYS_TIME_H
37 # include <sys/time.h>
45 #if defined(mingw32_TARGET_OS)
57 #if defined(mingw32_TARGET_OS)
58 /* -------------------- WINDOWS VERSION --------------------- */
64 PROCESS_INFORMATION pInfo;
67 ZeroMemory(&sInfo, sizeof(sInfo));
68 sInfo.cb = sizeof(sInfo);
70 if (!CreateProcess(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &sInfo, &pInfo)) {
71 /* The 'TRUE' says that the created process should share
72 handles with the current process. This is vital to ensure
73 that error messages sent to stderr actually appear on the screen.
74 Since we are going to wait for the process to terminate anyway,
75 there is no problem with such sharing. */
79 WaitForSingleObject(pInfo.hProcess, INFINITE);
80 if (GetExitCodeProcess(pInfo.hProcess, &retCode) == 0) return -1;
82 CloseHandle(pInfo.hProcess);
83 CloseHandle(pInfo.hThread);
88 /* -------------------- UNIX VERSION --------------------- */
91 rawSystem(HsAddr cmd, HsAddr args)
96 switch(pid = fork()) {
103 #ifdef HAVE_SETITIMER
104 /* Reset the itimers in the child, so it doesn't get plagued
105 * by SIGVTALRM interrupts.
107 struct timeval tv_null = { 0, 0 };
108 struct itimerval itv;
109 itv.it_interval = tv_null;
110 itv.it_value = tv_null;
111 setitimer(ITIMER_REAL, &itv, NULL);
112 setitimer(ITIMER_VIRTUAL, &itv, NULL);
113 setitimer(ITIMER_PROF, &itv, NULL);
122 while (waitpid(pid, &wstat, 0) < 0) {
123 if (errno != EINTR) {
128 if (WIFEXITED(wstat))
129 return WEXITSTATUS(wstat);
130 else if (WIFSIGNALED(wstat)) {
134 /* This should never happen */