2 * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
4 * $Id: rawSystem.c,v 1.1 2002/08/28 13:59:19 simonmar Exp $
6 * shell-less system Runtime Support
9 /* The itimer stuff in this module is non-posix */
10 /* #include "PosixSource.h" */
23 #ifdef HAVE_SYS_WAIT_H
27 # ifdef TIME_WITH_SYS_TIME
28 # include <sys/time.h>
31 # ifdef HAVE_SYS_TIME_H
32 # include <sys/time.h>
40 #if defined(mingw32_TARGET_OS)
45 rawSystemCmd(HsAddr cmd)
47 /* -------------------- WINDOWS VERSION --------------------- */
48 #if defined(mingw32_TARGET_OS)
50 PROCESS_INFORMATION pInfo;
53 sInfo.cb = sizeof(STARTUPINFO);
54 sInfo.lpReserved = NULL;
55 sInfo.lpReserved2 = NULL;
56 sInfo.cbReserved2 = 0;
57 sInfo.lpDesktop = NULL;
61 if (!CreateProcess(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &sInfo, &pInfo))
62 /* The 'TRUE' says that the created process should share
63 handles with the current process. This is vital to ensure
64 that error messages sent to stderr actually appear on the screen.
65 Since we are going to wait for the process to terminate anyway,
66 there is no problem with such sharing. */
69 WaitForSingleObject(pInfo.hProcess, INFINITE);
70 if (GetExitCodeProcess(pInfo.hProcess, &retCode) == 0) return -1;
71 CloseHandle(pInfo.hProcess);
72 CloseHandle(pInfo.hThread);
76 /* -------------------- UNIX VERSION --------------------- */
80 switch(pid = fork()) {
88 /* Reset the itimers in the child, so it doesn't get plagued
89 * by SIGVTALRM interrupts.
91 struct timeval tv_null = { 0, 0 };
93 itv.it_interval = tv_null;
94 itv.it_value = tv_null;
95 setitimer(ITIMER_REAL, &itv, NULL);
96 setitimer(ITIMER_VIRTUAL, &itv, NULL);
97 setitimer(ITIMER_PROF, &itv, NULL);
106 while (waitpid(pid, &wstat, 0) < 0) {
107 if (errno != EINTR) {
112 if (WIFEXITED(wstat))
113 return WEXITSTATUS(wstat);
114 else if (WIFSIGNALED(wstat)) {
118 /* This should never happen */