2 * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
4 * $Id: system.c,v 1.2 2001/07/31 11:51:09 simonmar Exp $
6 * system Runtime Support
9 /* The itimer stuff in this module is non-posix */
10 #define NON_POSIX_SOURCE
14 #if defined(mingw32_TARGET_OS)
21 /* -------------------- WINDOWS VERSION --------------------- */
22 #if defined(mingw32_TARGET_OS)
24 PROCESS_INFORMATION pInfo;
27 sInfo.cb = sizeof(STARTUPINFO);
28 sInfo.lpReserved = NULL;
29 sInfo.lpReserved2 = NULL;
30 sInfo.cbReserved2 = 0;
31 sInfo.lpDesktop = NULL;
35 if (!CreateProcess(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &sInfo, &pInfo))
36 /* The 'TRUE' says that the created process should share
37 handles with the current process. This is vital to ensure
38 that error messages sent to stderr actually appear on the screen.
39 Since we are going to wait for the process to terminate anyway,
40 there is no problem with such sharing. */
43 WaitForSingleObject(pInfo.hProcess, INFINITE);
44 if (GetExitCodeProcess(pInfo.hProcess, &retCode) == 0) return -1;
45 CloseHandle(pInfo.hProcess);
46 CloseHandle(pInfo.hThread);
50 /* -------------------- UNIX VERSION --------------------- */
54 switch(pid = fork()) {
62 /* Reset the itimers in the child, so it doesn't get plagued
63 * by SIGVTALRM interrupts.
65 struct timeval tv_null = { 0, 0 };
67 itv.it_interval = tv_null;
68 itv.it_value = tv_null;
69 setitimer(ITIMER_REAL, &itv, NULL);
70 setitimer(ITIMER_VIRTUAL, &itv, NULL);
71 setitimer(ITIMER_PROF, &itv, NULL);
75 execl("/bin/sh", "sh", "-c", cmd, NULL);
80 while (waitpid(pid, &wstat, 0) < 0) {
87 return WEXITSTATUS(wstat);
88 else if (WIFSIGNALED(wstat)) {
92 /* This should never happen */