1 /* -----------------------------------------------------------------------------
2 (c) The University of Glasgow 1995-2004
4 Our low-level exec() variant.
5 -------------------------------------------------------------------------- */
8 #if !defined(mingw32_HOST_OS) /* to the end */
10 /* Evidently non-Posix. */
11 /* #include "PosixSource.h" */
20 * We want the search semantics of execvp, but we want to provide our
21 * own environment, like execve. The following copyright applies to
22 * this code, as it is a derivative of execvp:
24 * Copyright (c) 1991 The Regents of the University of California.
25 * All rights reserved.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 execvpe(char *name, char *const argv[], char **envp)
61 int eacces=0, etxtbsy=0;
62 char *bp, *cur, *path, *buf = 0;
64 /* If it's an absolute or relative path name, it's easy. */
65 if (strchr(name, '/')) {
67 cur = path = buf = NULL;
71 /* Get the path we're searching. */
72 if (!(path = getenv("PATH"))) {
74 ln = confstr(_CS_PATH, NULL, 0);
75 if ((cur = path = malloc(ln + 1)) != NULL) {
77 (void) confstr (_CS_PATH, path + 1, ln);
80 if ((cur = path = malloc(1 + 1)) != NULL) {
86 cur = path = strdup(path);
88 if (path == NULL || (bp = buf = malloc(strlen(path)+strlen(name)+2)) == NULL)
93 if ((cur = strchr(cur, ':')) != NULL)
97 * It's a SHELL path -- double, leading and trailing colons mean the current
109 memcpy(buf + lp + 1, name, ln);
110 buf[lp + ln + 1] = '\0';
113 (void) execve(bp, argv, envp);
125 for (cnt = 0, ap = (char **) argv; *ap; ++ap, ++cnt)
127 if ((ap = malloc((cnt + 2) * sizeof(char *))) != NULL) {
128 memcpy(ap + 2, argv + 1, cnt * sizeof(char *));
132 (void) execve("/bin/sh", ap, envp);
139 (void) sleep(++etxtbsy);
158 /* Copied verbatim from ghc/lib/std/cbits/system.c. */
159 void pPrPr_disableITimers (void)
161 # ifdef HAVE_SETITIMER
162 /* Reset the itimers in the child, so it doesn't get plagued
163 * by SIGVTALRM interrupts.
165 struct timeval tv_null = { 0, 0 };
166 struct itimerval itv;
167 itv.it_interval = tv_null;
168 itv.it_value = tv_null;
169 setitimer(ITIMER_REAL, &itv, NULL);
170 setitimer(ITIMER_VIRTUAL, &itv, NULL);
171 setitimer(ITIMER_PROF, &itv, NULL);