aboutsummaryrefslogtreecommitdiffhomepage
path: root/cbits
diff options
context:
space:
mode:
authorGravatar Herbert Valerio Riedel <hvr@gnu.org>2014-12-06 15:39:12 +0100
committerGravatar Herbert Valerio Riedel <hvr@gnu.org>2014-12-06 15:47:36 +0100
commitf24ba78f68b2cbc4f4afadc8dd60fc2935357255 (patch)
treef0f82b0a48222905cf12da233c5b5b3eb2392cac /cbits
parent123fcba7125c3b94ad35c3d7dfe31c715a79a470 (diff)
Refactor local `execvpe(3)` implementation
The previous code was prone to conflicts with when the platform happens to expose a `execvpe(3)` implementation in its libc. This commit renames the internal implementation to `__hsunix_execvpe` as well as adding an autoconf-detection for the presence of `execvpe(3)`, in which case `__hsunix_execvpe()` forwards the call to `execvpe(3)`. Moreover, the code has been cleaned up to remove likely bitrotted CPP conditionals. This should fix #22 (This also partially addresses #11 on platforms which have a libc-provided `execvpe(3)`)
Diffstat (limited to 'cbits')
-rw-r--r--cbits/execvpe.c44
-rw-r--r--cbits/ghcrts.c14
2 files changed, 35 insertions, 23 deletions
diff --git a/cbits/execvpe.c b/cbits/execvpe.c
index 6ce1e9d..8c9d52d 100644
--- a/cbits/execvpe.c
+++ b/cbits/execvpe.c
@@ -2,19 +2,25 @@
(c) The University of Glasgow 1995-2004
Our low-level exec() variant.
+
+ Note: __hsunix_execvpe() is very similiar to the function
+ execvpe(3) as provided by glibc 2.11 and later. However, if
+ execvpe(3) is available, we use that instead.
+
-------------------------------------------------------------------------- */
#include "execvpe.h"
-#ifdef __GLASGOW_HASKELL__
-#include "Rts.h"
-#endif
+#include "HsUnixConfig.h"
-#if !(defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32)) /* to the end */
-#ifndef __QNXNTO__
-
-/* Evidently non-Posix. */
-/* #include "PosixSource.h" */
+#if HAVE_EXECVPE
+# define _GNU_SOURCE
+#endif
+#include <errno.h>
+#include <sys/types.h>
+#if HAVE_SYS_WAIT_H
+# include <sys/wait.h>
+#endif
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
@@ -59,8 +65,11 @@
*/
int
-execvpe(char *name, char *const argv[], char **envp)
+__hsunix_execvpe(const char *name, char *const argv[], char *const envp[])
{
+#if HAVE_EXECVPE
+ return execvpe(name, argv, envp);
+#else
register int lp, ln;
register char *p;
int eacces=0, etxtbsy=0;
@@ -75,18 +84,18 @@ execvpe(char *name, char *const argv[], char **envp)
/* Get the path we're searching. */
if (!(path = getenv("PATH"))) {
-#ifdef HAVE_CONFSTR
+# ifdef HAVE_CONFSTR
ln = confstr(_CS_PATH, NULL, 0);
if ((cur = path = malloc(ln + 1)) != NULL) {
path[0] = ':';
(void) confstr (_CS_PATH, path + 1, ln);
}
-#else
+# else
if ((cur = path = malloc(1 + 1)) != NULL) {
path[0] = ':';
path[1] = '\0';
}
-#endif
+# endif
} else
cur = path = strdup(path);
@@ -157,16 +166,5 @@ execvpe(char *name, char *const argv[], char **envp)
if (buf)
free(buf);
return (-1);
-}
-#endif
-
-
-/* Copied verbatim from ghc/lib/std/cbits/system.c. */
-void pPrPr_disableITimers (void)
-{
-#ifdef __GLASGOW_HASKELL__
- stopTimer();
#endif
}
-
-#endif
diff --git a/cbits/ghcrts.c b/cbits/ghcrts.c
new file mode 100644
index 0000000..1e0dc1c
--- /dev/null
+++ b/cbits/ghcrts.c
@@ -0,0 +1,14 @@
+#include "execvpe.h"
+
+#ifdef __GLASGOW_HASKELL__
+// for 'void StopTimer(void)' prototype
+# include "Rts.h"
+#endif
+
+/* Copied verbatim from ghc/lib/std/cbits/system.c. */
+void pPrPr_disableITimers (void)
+{
+#ifdef __GLASGOW_HASKELL__
+ stopTimer();
+#endif
+}