2 % (c) The GRASP/AQUA Project, Glasgow University, 1995
4 \subsection[posix.lc]{executeFile Runtime Support}
13 * We want the search semantics of execvp, but we want to provide our
14 * own environment, like execve. The following copyright applies to
15 * this code, as it is a derivative of execvp:
17 * Copyright (c) 1991 The Regents of the University of California.
18 * All rights reserved.
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
23 * 1. Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * 2. Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
28 * 3. All advertising materials mentioning features or use of this software
29 * must display the following acknowledgement:
30 * This product includes software developed by the University of
31 * California, Berkeley and its contributors.
32 * 4. Neither the name of the University nor the names of its contributors
33 * may be used to endorse or promote products derived from this software
34 * without specific prior written permission.
36 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
37 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
40 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
41 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
42 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
44 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
45 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50 execvpe(name, argv, envp)
58 char *bp, *cur, *path, *buf;
60 /* If it's an absolute or relative path name, it's easy. */
61 if (strchr(name, '/')) {
63 cur = path = buf = NULL;
67 /* Get the path we're searching. */
68 if (!(path = getenv("PATH"))) {
70 ln = confstr(_CS_PATH, NULL, 0);
71 if ((cur = path = malloc(ln + 1)) != NULL) {
73 (void) confstr (_CS_PATH, path + 1, ln);
76 if ((cur = path = malloc(1 + 1)) != NULL) {
82 cur = path = strdup(path);
84 if (path == NULL || (bp = buf = malloc(strlen(path)+strlen(name)+2)) == NULL)
90 if ((cur = strchr(cur, ':')) != NULL)
94 * It's a SHELL path -- double, leading and trailing colons mean the current
106 memcpy(buf + lp + 1, name, ln);
107 buf[lp + ln + 1] = '\0';
110 (void) execve(bp, argv, envp);
122 for (cnt = 0, ap = (char **) argv; *ap; ++ap, ++cnt)
124 if ((ap = malloc((cnt + 2) * sizeof(char *))) != NULL) {
125 memcpy(ap + 2, argv + 1, cnt * sizeof(char *));
129 (void) execve("/bin/sh", ap, envp);
136 (void) sleep(++etxtbsy);