diff options
author | Andi Gutmans <andi@php.net> | 2000-06-24 16:10:18 +0000 |
---|---|---|
committer | Andi Gutmans <andi@php.net> | 2000-06-24 16:10:18 +0000 |
commit | 4b5e7d6618f8ea1b3a9f24376593bb44abb8a1ae (patch) | |
tree | 496a52dcd684543f2cc1cedb96c7db69e8ed2d33 | |
parent | dfaaa8ff953c5c9a947ae45f1d0eb060f23f7364 (diff) | |
download | php-git-4b5e7d6618f8ea1b3a9f24376593bb44abb8a1ae.tar.gz |
- Only use VIRTUAL_DIR in ZTS mode until it is thoroughly tested.
- Mutex popen() in Windows as the UNIX trick doesn't work there.
-rw-r--r-- | main/php.h | 8 | ||||
-rw-r--r-- | main/php_virtual_cwd.c | 53 | ||||
-rw-r--r-- | main/php_virtual_cwd.h | 19 |
3 files changed, 71 insertions, 9 deletions
diff --git a/main/php.h b/main/php.h index ef79abba16..f1d743faab 100644 --- a/main/php.h +++ b/main/php.h @@ -284,7 +284,10 @@ PHPAPI int cfg_get_string(char *varname, char **result); #define PUTS_H(str) php_header_write((str), strlen((str))) #define PUTC_H(c) (php_header_write(&(c), 1), (c)) +#ifdef ZTS #define VIRTUAL_DIR +#endif + #include "php_virtual_cwd.h" /* Virtual current directory support */ @@ -308,12 +311,7 @@ PHPAPI int cfg_get_string(char *varname, char **result); #define V_MKDIR(pathname, mode) virtual_mkdir(pathname, mode) #define V_RMDIR(pathname) virtual_rmdir(pathname) #define V_OPENDIR(pathname) virtual_opendir(pathname) -#ifdef PHP_WIN32 -/* Under Windows the "cd /cwd ; command" trick doesn't work */ -#define V_POPEN(command, type) popen(command, type) -#else #define V_POPEN(command, type) virtual_popen(command, type) -#endif #else diff --git a/main/php_virtual_cwd.c b/main/php_virtual_cwd.c index efa4c965d7..abf0c2037b 100644 --- a/main/php_virtual_cwd.c +++ b/main/php_virtual_cwd.c @@ -12,10 +12,11 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Authors: | - | | + | Authors: Andi Gutmans <andi@zend.com> | + | Sascha Schumann <ss@schumann.cx> | +----------------------------------------------------------------------+ - */ +*/ + #include <sys/types.h> #include <sys/stat.h> #include <string.h> @@ -39,6 +40,11 @@ #include "TSRM.h" #endif +/* Only need mutex for popen() in Windows because it doesn't chdir() on UNIX */ +#ifdef ZEND_WIN32 +MUTEX_T cwd_mutex; +#endif + ZEND_DECLARE_MODULE_GLOBALS(cwd); cwd_state main_cwd_state; /* True global */ @@ -158,7 +164,7 @@ static void cwd_globals_dtor(zend_cwd_globals *cwd_globals) CWD_API void virtual_cwd_startup(void) { - char cwd[1024]; /* Should probably use system define here */ + char cwd[MAXPATHLEN]; /* Should probably use system define here */ char *result; result = getcwd(cwd, sizeof(cwd)); @@ -169,6 +175,9 @@ CWD_API void virtual_cwd_startup(void) main_cwd_state.cwd_length = strlen(cwd); ZEND_INIT_MODULE_GLOBALS(cwd, cwd_globals_ctor, cwd_globals_dtor); +#ifdef ZEND_WIN32 + cwd_mutex = tsrm_mutex_alloc(); +#endif } CWD_API void virtual_cwd_activate(char *filename) @@ -186,6 +195,10 @@ CWD_API void virtual_cwd_shutdown(void) #ifndef ZTS cwd_globals_dtor(&cwd_globals); #endif +#ifdef ZEND_WIN32 + tsrm_mutex_free(cwd_mutex); +#endif + free(main_cwd_state.cwd); /* Don't use CWD_STATE_FREE because the non global states will probably use emalloc()/efree() */ } @@ -559,6 +572,8 @@ CWD_API DIR *virtual_opendir(const char *pathname) return retval; } +#ifndef ZEND_WIN32 + CWD_API FILE *virtual_popen(const char *command, const char *type) { int command_length; @@ -593,6 +608,36 @@ CWD_API FILE *virtual_popen(const char *command, const char *type) return retval; } +#else + +/* On Windows the trick of prepending "cd cwd; " doesn't work so we need to perform + a real chdir() and mutex it + */ +CWD_API FILE *virtual_popen(const char *command, const char *type) +{ + char prev_cwd[MAXPATHLEN]; + char *getcwd_result; + FILE *retval; + CWDLS_FETCH(); + + getcwd_result = getcwd(prev_cwd, MAXPATHLEN); + if (!getcwd_result) { + return NULL; + } + + tsrm_mutex_lock(cwd_mutex); + + chdir(CWDG(cwd).cwd); + retval = popen(command, type); + chdir(prev_cwd); + + tsrm_mutex_unlock(cwd_mutex); + + return retval; +} + +#endif + #if 0 main(void) diff --git a/main/php_virtual_cwd.h b/main/php_virtual_cwd.h index bfe9f08eb2..812bbc26bf 100644 --- a/main/php_virtual_cwd.h +++ b/main/php_virtual_cwd.h @@ -1,3 +1,22 @@ +/* + +----------------------------------------------------------------------+ + | PHP version 4.0 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 2.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | http://www.php.net/license/2_02.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Andi Gutmans <andi@zend.com> | + | Sascha Schumann <ss@schumann.cx> | + +----------------------------------------------------------------------+ +*/ + #ifndef VIRTUAL_CWD_H #define VIRTUAL_CWD_H |