2 * (c) The University of Glasgow 1994-2004
4 * WARNING: this file is here for backwards compatibility only. It is
5 * not included as part of the base package, but is #included into the
6 * compiler and the runghc utility when building either of these with
7 * an old version of GHC.
9 * shell-less system Runtime Support (see System.Cmd.rawSystem).
12 /* The itimer stuff in this module is non-posix */
13 /* #include "PosixSource.h" */
15 #include "../../../includes/ghcconfig.h"
26 #ifdef HAVE_SYS_WAIT_H
30 # ifdef TIME_WITH_SYS_TIME
31 # include <sys/time.h>
34 # ifdef HAVE_SYS_TIME_H
35 # include <sys/time.h>
43 #if defined(mingw32_HOST_OS)
55 #if defined(mingw32_HOST_OS)
56 /* -------------------- WINDOWS VERSION --------------------- */
62 PROCESS_INFORMATION pInfo;
65 ZeroMemory(&sInfo, sizeof(sInfo));
66 sInfo.cb = sizeof(sInfo);
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. */
75 errno = EINVAL; // ToDo: wrong, caller should use GetLastError()
78 WaitForSingleObject(pInfo.hProcess, INFINITE);
79 if (GetExitCodeProcess(pInfo.hProcess, &retCode) == 0) {
80 errno = EINVAL; // ToDo: wrong, caller should use GetLastError()
84 CloseHandle(pInfo.hProcess);
85 CloseHandle(pInfo.hThread);
90 /* -------------------- UNIX VERSION --------------------- */
93 rawSystem(char *cmd, char **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 */