From 36272215efc0bdbea1b156dc40441a1f790a8975 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Tue, 14 Feb 2017 13:53:11 +0100 Subject: [PATCH] PR#6903: Unix.execvpe doesn't change environment on Cygwin Old implementation was based on changing the "environ" variable and calling "execvp". It doesn't work under Cygwin and possibly other OS. New implementation builds on "execve" after searching the executable in PATH ourselves. --- Changes | 3 +++ otherlibs/unix/execvp.c | 21 ++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Changes b/Changes index a7eed8e38c11..64d92a2d9dee 100644 --- a/Changes +++ b/Changes @@ -277,6 +277,9 @@ Next version (4.05.0): uninitialized caml_global_data (only changes the bytecode behavior) (Gabriel Scherer, review by Xavier Leroy) +- PR#6903: Unix.execvpe doesn't change environment on Cygwin + (Xavier Leroy) + - PR#7216, GPR#949: don't require double parens in Functor((val x)) (Jacques Garrigue, review by Valentin Gatien-Baron) diff --git a/otherlibs/unix/execvp.c b/otherlibs/unix/execvp.c index 338de2a29b7c..d521adcff7ef 100644 --- a/otherlibs/unix/execvp.c +++ b/otherlibs/unix/execvp.c @@ -15,6 +15,8 @@ #include #include +#define CAML_INTERNALS +#include #include "unixsupport.h" #ifndef _WIN32 @@ -30,22 +32,23 @@ CAMLprim value unix_execvp(value path, value args) caml_stat_free((char *) argv); uerror("execvp", path); return Val_unit; /* never reached, but suppress warnings */ - /* from smart compilers */ + /* from smart compilers */ } CAMLprim value unix_execvpe(value path, value args, value env) { + char * exefile; char ** argv; - char ** saved_environ; + char ** envp; caml_unix_check_path(path, "execvpe"); + exefile = caml_search_exe_in_path(String_val(path)); argv = cstringvect(args, "execvpe"); - saved_environ = environ; - environ = cstringvect(env, "execvpe"); - (void) execvp(String_val(path), argv); + envp = cstringvect(env, "execvpe"); + (void) execve(exefile, argv, envp); + caml_stat_free(exefile); caml_stat_free((char *) argv); - caml_stat_free((char *) environ); - environ = saved_environ; - uerror("execvp", path); + caml_stat_free((char *) envp); + uerror("execvpe", path); return Val_unit; /* never reached, but suppress warnings */ - /* from smart compilers */ + /* from smart compilers */ }