uclibc-0007-libc-add-non-standard-execvpe-function.patch 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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
  5. [Gustavo]: Drop TODO modification to make it compatible
  6. Signed-off-by: Henning Heinold <heinold@inf.fu-berlin.de>
  7. Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
  8. ---
  9. include/unistd.h | 8 ++++++++
  10. libc/unistd/exec.c | 38 +++++++++++++++++++++++++++++++++-----
  11. libc/unistd/execvpe.c | 7 +++++++
  12. 4 files changed, 52 insertions(+), 5 deletions(-)
  13. create mode 100644 libc/unistd/execvpe.c
  14. diff --git a/include/unistd.h b/include/unistd.h
  15. index feadf93..9479554 100644
  16. --- a/include/unistd.h
  17. +++ b/include/unistd.h
  18. @@ -619,6 +619,14 @@ extern int execlp (const char *__file, const char *__arg, ...)
  19. __THROW __nonnull ((1));
  20. libc_hidden_proto(execlp)
  21. +#ifdef __USE_GNU
  22. +/* Execute FILE, searching in the `PATH' environment variable if it contains
  23. + no slashes, with arguments ARGV and environment from a pointer */
  24. +extern int execvpe (__const char *__file, char *__const __argv[], char *__const __envp[])
  25. + __THROW __nonnull ((1));
  26. +libc_hidden_proto(execvpe)
  27. +#endif
  28. +
  29. #if defined __USE_MISC || defined __USE_XOPEN
  30. /* Add INC to priority of the current process. */
  31. diff --git a/libc/unistd/exec.c b/libc/unistd/exec.c
  32. index ba92989..8fa42e5 100644
  33. --- a/libc/unistd/exec.c
  34. +++ b/libc/unistd/exec.c
  35. @@ -32,6 +32,8 @@
  36. /**********************************************************************/
  37. #define EXEC_FUNC_COMMON 0
  38. #define EXEC_FUNC_EXECVP 1
  39. +#define EXEC_FUNC_EXECVPE 2
  40. +
  41. #if defined(__ARCH_USE_MMU__)
  42. /* We have an MMU, so use alloca() to grab space for buffers and arg lists. */
  43. @@ -58,6 +60,7 @@
  44. * execle(a) -> execve(-)
  45. * execv(-) -> execve(-)
  46. * execvp(a) -> execve(-)
  47. + * execvpe(a) -> execve(-)
  48. */
  49. # define EXEC_ALLOC_SIZE(VAR) /* nothing to do */
  50. @@ -219,15 +222,18 @@ libc_hidden_def(execlp)
  51. #endif
  52. /**********************************************************************/
  53. -#ifdef L_execvp
  54. +#if defined (L_execvp) || defined(L_execvpe)
  55. /* Use a default path that matches glibc behavior, since SUSv3 says
  56. * this is implementation-defined. The default is current working dir,
  57. * /bin, and then /usr/bin. */
  58. static const char default_path[] = ":/bin:/usr/bin";
  59. -
  60. +#if defined (L_execvp)
  61. int execvp(const char *path, char *const argv[])
  62. +#elif defined (L_execvpe)
  63. +int execvpe(const char *path, char *const argv[], char *const envp[])
  64. +#endif
  65. {
  66. char *buf = NULL;
  67. char *p;
  68. @@ -245,7 +251,11 @@ int execvp(const char *path, char *const argv[])
  69. }
  70. if (strchr(path, '/')) {
  71. +#if defined (L_execvp)
  72. execve(path, argv, __environ);
  73. +#elif defined (L_execvpe)
  74. + execve(path, argv, envp);
  75. +#endif
  76. if (errno == ENOEXEC) {
  77. char **nargv;
  78. EXEC_ALLOC_SIZE(size2) /* Do NOT add a semicolon! */
  79. @@ -254,11 +264,19 @@ int execvp(const char *path, char *const argv[])
  80. /* Need the dimension - 1. We omit counting the trailing
  81. * NULL but we actually omit the first entry. */
  82. for (n=0 ; argv[n] ; n++) {}
  83. +#if defined (L_execvp)
  84. nargv = (char **) EXEC_ALLOC((n+2) * sizeof(char *), size2, EXEC_FUNC_EXECVP);
  85. +#elif defined (L_execvpe)
  86. + nargv = (char **) EXEC_ALLOC((n+2) * sizeof(char *), size2, EXEC_FUNC_EXECVPE);
  87. +#endif
  88. nargv[0] = argv[0];
  89. nargv[1] = (char *)path;
  90. memcpy(nargv+2, argv+1, n*sizeof(char *));
  91. +#if defined (L_execvp)
  92. execve("/bin/sh", nargv, __environ);
  93. +#elif defined (L_execvpe)
  94. + execve("/bin/sh", nargv, envp);
  95. +#endif
  96. EXEC_FREE(nargv, size2);
  97. }
  98. } else {
  99. @@ -277,8 +295,11 @@ int execvp(const char *path, char *const argv[])
  100. return -1;
  101. }
  102. len = (FILENAME_MAX - 1) - plen;
  103. -
  104. +#if defined (L_execvp)
  105. buf = EXEC_ALLOC(FILENAME_MAX, size, EXEC_FUNC_EXECVP);
  106. +#elif defined (L_execvpe)
  107. + buf = EXEC_ALLOC(FILENAME_MAX, size, EXEC_FUNC_EXECVPE);
  108. +#endif
  109. {
  110. int seen_small = 0;
  111. s0 = buf + len;
  112. @@ -300,8 +321,11 @@ int execvp(const char *path, char *const argv[])
  113. s[plen-1] = '/';
  114. }
  115. +#if defined (L_execvp)
  116. execve(s, argv, __environ);
  117. -
  118. +#elif defined (L_execvpe)
  119. + execve(s, argv, envp);
  120. +#endif
  121. seen_small = 1;
  122. if (errno == ENOEXEC) {
  123. @@ -325,7 +349,11 @@ int execvp(const char *path, char *const argv[])
  124. return -1;
  125. }
  126. +#if defined (L_execvp)
  127. libc_hidden_def(execvp)
  128. -
  129. +#elif defined (L_execvpe)
  130. +libc_hidden_def(execvpe)
  131. #endif
  132. +
  133. +#endif /* #if defined (L_execvp) || defined(L_execvpe) */
  134. /**********************************************************************/
  135. diff --git a/libc/unistd/execvpe.c b/libc/unistd/execvpe.c
  136. new file mode 100644
  137. index 0000000..c3c1e43
  138. --- /dev/null
  139. +++ b/libc/unistd/execvpe.c
  140. @@ -0,0 +1,7 @@
  141. +/* Copyright (C) 2011-2013 Hennning Heinold <heinold@inf.fu-berlin.de>
  142. + *
  143. + * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
  144. + */
  145. +
  146. +#define L_execvpe
  147. +#include "exec.c"
  148. --
  149. 1.8.1.5