1 From 0eb30761a26c46aaf555464114851202ae9c27bd Mon Sep 17 00:00:00 2001
2 From: Henning Heinold <heinold@inf.fu-berlin.de>
3 Date: Sat, 4 Jun 2011 21:23:15 +0200
4 Subject: [PATCH] libc: add non standard execvpe function
6 [Gustavo]: Drop TODO modification to make it compatible
7 Signed-off-by: Henning Heinold <heinold@inf.fu-berlin.de>
8 Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
10 include/unistd.h | 8 ++++++++
11 libc/unistd/exec.c | 38 +++++++++++++++++++++++++++++++++-----
12 libc/unistd/execvpe.c | 7 +++++++
13 4 files changed, 52 insertions(+), 5 deletions(-)
14 create mode 100644 libc/unistd/execvpe.c
16 diff --git a/include/unistd.h b/include/unistd.h
17 index feadf93..9479554 100644
18 --- a/include/unistd.h
19 +++ b/include/unistd.h
20 @@ -619,6 +619,14 @@ extern int execlp (const char *__file, const char *__arg, ...)
21 __THROW __nonnull ((1));
22 libc_hidden_proto(execlp)
25 +/* Execute FILE, searching in the `PATH' environment variable if it contains
26 + no slashes, with arguments ARGV and environment from a pointer */
27 +extern int execvpe (__const char *__file, char *__const __argv[], char *__const __envp[])
28 + __THROW __nonnull ((1));
29 +libc_hidden_proto(execvpe)
33 #if defined __USE_MISC || defined __USE_XOPEN
34 /* Add INC to priority of the current process. */
35 diff --git a/libc/unistd/exec.c b/libc/unistd/exec.c
36 index ba92989..8fa42e5 100644
37 --- a/libc/unistd/exec.c
38 +++ b/libc/unistd/exec.c
40 /**********************************************************************/
41 #define EXEC_FUNC_COMMON 0
42 #define EXEC_FUNC_EXECVP 1
43 +#define EXEC_FUNC_EXECVPE 2
45 #if defined(__ARCH_USE_MMU__)
47 /* We have an MMU, so use alloca() to grab space for buffers and arg lists. */
49 * execle(a) -> execve(-)
50 * execv(-) -> execve(-)
51 * execvp(a) -> execve(-)
52 + * execvpe(a) -> execve(-)
55 # define EXEC_ALLOC_SIZE(VAR) /* nothing to do */
56 @@ -219,15 +222,18 @@ libc_hidden_def(execlp)
59 /**********************************************************************/
61 +#if defined (L_execvp) || defined(L_execvpe)
64 /* Use a default path that matches glibc behavior, since SUSv3 says
65 * this is implementation-defined. The default is current working dir,
66 * /bin, and then /usr/bin. */
67 static const char default_path[] = ":/bin:/usr/bin";
69 +#if defined (L_execvp)
70 int execvp(const char *path, char *const argv[])
71 +#elif defined (L_execvpe)
72 +int execvpe(const char *path, char *const argv[], char *const envp[])
77 @@ -245,7 +251,11 @@ int execvp(const char *path, char *const argv[])
80 if (strchr(path, '/')) {
81 +#if defined (L_execvp)
82 execve(path, argv, __environ);
83 +#elif defined (L_execvpe)
84 + execve(path, argv, envp);
86 if (errno == ENOEXEC) {
88 EXEC_ALLOC_SIZE(size2) /* Do NOT add a semicolon! */
89 @@ -254,11 +264,19 @@ int execvp(const char *path, char *const argv[])
90 /* Need the dimension - 1. We omit counting the trailing
91 * NULL but we actually omit the first entry. */
92 for (n=0 ; argv[n] ; n++) {}
93 +#if defined (L_execvp)
94 nargv = (char **) EXEC_ALLOC((n+2) * sizeof(char *), size2, EXEC_FUNC_EXECVP);
95 +#elif defined (L_execvpe)
96 + nargv = (char **) EXEC_ALLOC((n+2) * sizeof(char *), size2, EXEC_FUNC_EXECVPE);
99 nargv[1] = (char *)path;
100 memcpy(nargv+2, argv+1, n*sizeof(char *));
101 +#if defined (L_execvp)
102 execve("/bin/sh", nargv, __environ);
103 +#elif defined (L_execvpe)
104 + execve("/bin/sh", nargv, envp);
106 EXEC_FREE(nargv, size2);
109 @@ -277,8 +295,11 @@ int execvp(const char *path, char *const argv[])
112 len = (FILENAME_MAX - 1) - plen;
114 +#if defined (L_execvp)
115 buf = EXEC_ALLOC(FILENAME_MAX, size, EXEC_FUNC_EXECVP);
116 +#elif defined (L_execvpe)
117 + buf = EXEC_ALLOC(FILENAME_MAX, size, EXEC_FUNC_EXECVPE);
122 @@ -300,8 +321,11 @@ int execvp(const char *path, char *const argv[])
126 +#if defined (L_execvp)
127 execve(s, argv, __environ);
129 +#elif defined (L_execvpe)
130 + execve(s, argv, envp);
134 if (errno == ENOEXEC) {
135 @@ -325,7 +349,11 @@ int execvp(const char *path, char *const argv[])
139 +#if defined (L_execvp)
140 libc_hidden_def(execvp)
142 +#elif defined (L_execvpe)
143 +libc_hidden_def(execvpe)
146 +#endif /* #if defined (L_execvp) || defined(L_execvpe) */
147 /**********************************************************************/
148 diff --git a/libc/unistd/execvpe.c b/libc/unistd/execvpe.c
150 index 0000000..c3c1e43
152 +++ b/libc/unistd/execvpe.c
154 +/* Copyright (C) 2011-2013 Hennning Heinold <heinold@inf.fu-berlin.de>
156 + * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.