From 514b6a95a5e4cb26d9dd24f5c37da1f579c6a918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Sat, 2 Mar 2013 22:42:05 +0000 Subject: [PATCH] [INTERPRETER] * NEW: Defining the PWD environment variable in a SHELL or EXEC instruction changes the working directory of the child process. git-svn-id: svn://localhost/gambas/trunk@5569 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- main/gbx/gbx_c_process.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/main/gbx/gbx_c_process.c b/main/gbx/gbx_c_process.c index f8676d7e4..e6fe9cb0a 100644 --- a/main/gbx/gbx_c_process.c +++ b/main/gbx/gbx_c_process.c @@ -405,6 +405,7 @@ static void run_process(CPROCESS *process, int mode, void *cmd, CARRAY *env) CARRAY *array; int i, n; sigset_t sig, old; + bool pwd; /* for terminal */ int fd_master = -1; @@ -669,8 +670,7 @@ static void run_process(CPROCESS *process, int mode, void *cmd, CARRAY *env) } } - // Return to the parent working directory - FILE_chdir(PROJECT_oldcwd); + pwd = FALSE; if (env) { @@ -681,9 +681,15 @@ static void run_process(CPROCESS *process, int mode, void *cmd, CARRAY *env) str = ((char **)env->data)[i]; if (putenv(str)) ERROR_warning("cannot set environment string: %s", str); + if (strncmp(str, "PWD=", 4) == 0 && chdir(&str[4]) == 0) + pwd = TRUE; } } + // Return to the parent working directory if the PWD environment variable has not been set + if (!pwd) + FILE_chdir(PROJECT_oldcwd); + execvp(argv[0], (char **)argv); //execve(argv[0], (char **)argv, environ); abort_child(CHILD_CANNOT_EXEC);