From e2362476ae303d4b980afc8653aca00af758d9e8 Mon Sep 17 00:00:00 2001 From: Taco Hoekwater Date: Fri, 23 Apr 2010 16:53:43 +0000 Subject: fix handling of the environment in luatex's os.exec()/os.spawn() on WIN32 git-svn-id: svn://tug.org/texlive/trunk@17975 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/web2c/luatexdir/ChangeLog | 5 +++ Build/source/texk/web2c/luatexdir/lua/loslibext.c | 50 ++++++++++++++++------ .../texk/web2c/luatexdir/luatex_svnversion.h | 2 +- 3 files changed, 44 insertions(+), 13 deletions(-) (limited to 'Build/source/texk/web2c') diff --git a/Build/source/texk/web2c/luatexdir/ChangeLog b/Build/source/texk/web2c/luatexdir/ChangeLog index be2f95db99d..fb508143f96 100644 --- a/Build/source/texk/web2c/luatexdir/ChangeLog +++ b/Build/source/texk/web2c/luatexdir/ChangeLog @@ -1,3 +1,8 @@ +2010-04-23 Taco Hoekwater + + * lua/loslibext.c: fix os.exec() and os.spawn() + * luatex_svnversion.h: updated to reflect the version of 0.60.x branch + 2010-04-23 Taco Hoekwater * new import from luatex repository (HEAD of 0.60.x branch) diff --git a/Build/source/texk/web2c/luatexdir/lua/loslibext.c b/Build/source/texk/web2c/luatexdir/lua/loslibext.c index 467dc975670..4cc6af2c285 100644 --- a/Build/source/texk/web2c/luatexdir/lua/loslibext.c +++ b/Build/source/texk/web2c/luatexdir/lua/loslibext.c @@ -25,7 +25,7 @@ #include static const char _svn_version[] = - "$Id: loslibext.c 3634 2010-04-19 19:52:48Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/branches/0.60.x/source/texk/web2c/luatexdir/lua/loslibext.c $"; + "$Id: loslibext.c 3644 2010-04-23 16:35:00Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/branches/0.60.x/source/texk/web2c/luatexdir/lua/loslibext.c $"; #if defined(_WIN32) || defined(__NT__) # define MKDIR(a,b) mkdir(a) @@ -111,13 +111,33 @@ static const char _svn_version[] = #define DONT_REALLY_EXIT 1 +/* Note: under WIN32, |environ| is nothing but a copy of the actual + environment as it was during program startup. That variable + can then be changed (which is a little odd), but such changes + do not survive in the actual environment *unless* they are + passed on down in e.g. |_execvpe|, when they would be inherited + by the child process. + + This gives trouble because some parts of the texk code actually + change the contents of the |environ| variable as a side-effect + of other processing, and that explains why the current code does + not use |environ| at all for the moment. + + The API is kept in place for now, just in case. Thanks to Tomek + for the patch and the persistence in tracking this down. +*/ + #ifdef _WIN32 # include -# define spawn_command(a,b,c) _spawnvpe(_P_WAIT,(const char *)a,(const char* const*)b,(const char* const*)c) +# define spawn_command(a,b,c) c ? \ + _spawnvpe(_P_WAIT,(const char *)a,(const char* const*)b,(const char* const*)c) : \ + _spawnvp(_P_WAIT,(const char *)a,(const char* const*)b) # if DONT_REALLY_EXIT # define exec_command(a,b,c) exit(spawn_command((a),(b),(c))) # else -# define exec_command(a,b,c) _execvpe((const char *)a,(const char* const*)b,(const char* const*)c) +# define exec_command(a,b,c) c ? \ + _execvpe((const char *)a,(const char* const*)b,(const char* const*)c) : \ + _execvp((const char *)a,(const char* const*)b) # endif #else # include @@ -130,7 +150,7 @@ static int exec_command(const char *file, char *const *argv, char *const *envp) size_t prefixlen, filelen, totallen; if (strchr(file, '/')) /* Specific path */ - return execve(file, argv, envp); + return envp ? execv(file, argv) : execve(file, argv, envp); filelen = strlen(file); path = NULL; @@ -170,7 +190,11 @@ static int exec_command(const char *file, char *const *argv, char *const *envp) } path[totallen] = '\0'; - execve(path, argv, envp); + if (envp) { + execve(path, argv, envp); + } else { + execv(path, argv); + } free(path); path = NULL; if (errno == E2BIG || errno == ENOEXEC || @@ -411,7 +435,8 @@ static int os_exec(lua_State * L) char *runcmd = NULL; char *safecmd = NULL, *cmdname = NULL; char **cmdline = NULL; - + char **envblock = NULL; + if (lua_gettop(L) != 1) { lua_pushnil(L); lua_pushliteral(L, "invalid arguments passed"); @@ -444,16 +469,16 @@ static int os_exec(lua_State * L) if (allow > 0 && cmdline != NULL && runcmd != NULL) { #if defined(_WIN32) && DONT_REALLY_EXIT if (allow == 2) - exec_command(safecmd, cmdline, environ); + exec_command(safecmd, cmdline, envblock); else - exec_command(runcmd, cmdline, environ); + exec_command(runcmd, cmdline, envblock); #else { int r; if (allow == 2) - r = exec_command(safecmd, cmdline, environ); + r = exec_command(safecmd, cmdline, envblock); else - r = exec_command(runcmd, cmdline, environ); + r = exec_command(runcmd, cmdline, envblock); if (r == -1) { lua_pushnil(L); lua_pushfstring(L, "%s: %s", runcmd, strerror(errno)); @@ -491,6 +516,7 @@ static int os_spawn(lua_State * L) char *runcmd = NULL; char *safecmd = NULL, *cmdname = NULL; char **cmdline = NULL; + char **envblock = NULL; int i; if (lua_gettop(L) != 1) { @@ -523,9 +549,9 @@ static int os_spawn(lua_State * L) } if (allow > 0 && cmdline != NULL && runcmd != NULL) { if (allow == 2) - i = spawn_command(safecmd, cmdline, environ); + i = spawn_command(safecmd, cmdline, envblock); else - i = spawn_command(runcmd, cmdline, environ); + i = spawn_command(runcmd, cmdline, envblock); if (safecmd) free(safecmd); if (cmdname) diff --git a/Build/source/texk/web2c/luatexdir/luatex_svnversion.h b/Build/source/texk/web2c/luatexdir/luatex_svnversion.h index 4e5a14a4bca..7cf059583a3 100644 --- a/Build/source/texk/web2c/luatexdir/luatex_svnversion.h +++ b/Build/source/texk/web2c/luatexdir/luatex_svnversion.h @@ -1 +1 @@ -#define luatex_svn_revision 3634 +#define luatex_svn_revision 3644 -- cgit v1.2.3