Skip to content

Commit

Permalink
PR#6903: Unix.execvpe doesn't change environment on Cygwin
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
xavierleroy committed Feb 14, 2017
1 parent 838ea0f commit 3627221
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Changes
Expand Up @@ -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)

Expand Down
21 changes: 12 additions & 9 deletions otherlibs/unix/execvp.c
Expand Up @@ -15,6 +15,8 @@

#include <caml/mlvalues.h>
#include <caml/memory.h>
#define CAML_INTERNALS
#include <caml/osdeps.h>
#include "unixsupport.h"

#ifndef _WIN32
Expand All @@ -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 */
}

0 comments on commit 3627221

Please sign in to comment.