tsukada
ttsuk****@users*****
2003年 2月 11日 (火) 12:09:20 JST
ttsukada 03/02/11 12:09:19 Modified: . TSRM.c TSRM.h tsrm_config.nw.h tsrm_config_common.h tsrm_nw.c tsrm_nw.h tsrm_virtual_cwd.c tsrm_virtual_cwd.h tsrm_win32.c tsrm_win32.h Log: merge Revision Changes Path 1.6 +45 -5 TSRM/TSRM.c Index: TSRM.c =================================================================== RCS file: /cvsroot/php-i18n/TSRM/TSRM.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- TSRM.c 6 Oct 2002 21:18:39 -0000 1.5 +++ TSRM.c 11 Feb 2003 03:09:19 -0000 1.6 @@ -79,7 +79,7 @@ } \ } #else -#define TSRM_ERROR +#define TSRM_ERROR(args) #define TSRM_SAFE_RETURN_RSRC(array, offset, range) \ if (offset==0) { \ return &array; \ @@ -158,6 +158,9 @@ next_p = p->next; for (j=0; j<id_count; j++) { + if (resource_types_table && resource_types_table[j].dtor) { + resource_types_table[j].dtor(p->storage[j], &p->storage); + } free(p->storage[j]); } free(p->storage); @@ -290,6 +293,15 @@ int hash_value; tsrm_tls_entry *thread_resources; +#ifdef NETWARE + /* The below if loop is added for NetWare to fix an abend while unloading PHP + * when an Apache unload command is issued on the system console. + * While exiting from PHP, at the end for some reason, this function is called + * with tsrm_tls_table = NULL. When this happened, the server abends when + * tsrm_tls_table is accessed since it is NULL. + */ + if(tsrm_tls_table) { +#endif if (!th_id) { #if defined(PTHREADS) /* Fast path for looking up the resources for the current @@ -352,6 +364,9 @@ * changes to the structure as we read it. */ TSRM_SAFE_RETURN_RSRC(thread_resources->storage, id, thread_resources->count); +#ifdef NETWARE + } /* if(tsrm_tls_table) */ +#endif } @@ -419,7 +434,12 @@ #ifdef TSRM_WIN32 return GetCurrentThreadId(); #elif defined(NETWARE) - return NXThreadGetId(); + /* There seems to be some problem with the LibC call: NXThreadGetId(). + * Due to this, the PHPMyAdmin application is abending in PHP calls. + * Used the call, kCurrentThread instead and it works fine. + */ +/* return NXThreadGetId(); */ + return kCurrentThread(); #elif defined(GNUPTH) return pth_self(); #elif defined(PTHREADS) @@ -441,16 +461,23 @@ { MUTEX_T mutexp; #ifdef NETWARE - long flags = 0; /* Don't require NX_MUTEX_RECURSIVE, I guess */ +#ifndef USE_MPK + /* To use the Recursive Mutex Locking of LibC */ + long flags = NX_MUTEX_RECURSIVE; NXHierarchy_t order = 0; NX_LOCK_INFO_ALLOC (lockInfo, "PHP-TSRM", 0); -#endif +#endif +#endif #ifdef TSRM_WIN32 mutexp = malloc(sizeof(CRITICAL_SECTION)); InitializeCriticalSection(mutexp); #elif defined(NETWARE) - mutexp = NXMutexAlloc(flags, order, &lockInfo); /* return value ignored for now */ +#ifdef USE_MPK + mutexp = kMutexAlloc((BYTE*)"PHP-TSRM"); +#else + mutexp = NXMutexAlloc(flags, order, &lockInfo); +#endif #elif defined(GNUPTH) mutexp = (MUTEX_T) malloc(sizeof(*mutexp)); pth_mutex_init(mutexp); @@ -481,8 +508,13 @@ if (mutexp) { #ifdef TSRM_WIN32 DeleteCriticalSection(mutexp); + free(mutexp); #elif defined(NETWARE) +#ifdef USE_MPK + kMutexFree(mutexp); +#else NXMutexFree(mutexp); +#endif #elif defined(GNUPTH) free(mutexp); #elif defined(PTHREADS) @@ -513,7 +545,11 @@ EnterCriticalSection(mutexp); return 1; #elif defined(NETWARE) +#ifdef USE_MPK + return kMutexLock(mutexp); +#else return NXLock(mutexp); +#endif #elif defined(GNUPTH) return pth_mutex_acquire(mutexp, 0, NULL); #elif defined(PTHREADS) @@ -540,7 +576,11 @@ LeaveCriticalSection(mutexp); return 1; #elif defined(NETWARE) +#ifdef USE_MPK + return kMutexUnlock(mutexp); +#else return NXUnlock(mutexp); +#endif #elif defined(GNUPTH) return pth_mutex_release(mutexp); #elif defined(PTHREADS) 1.6 +8 -0 TSRM/TSRM.h Index: TSRM.h =================================================================== RCS file: /cvsroot/php-i18n/TSRM/TSRM.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- TSRM.h 6 Oct 2002 21:18:39 -0000 1.5 +++ TSRM.h 11 Feb 2003 03:09:19 -0000 1.6 @@ -40,7 +40,11 @@ # include <windows.h> #elif defined(NETWARE) # include <nks/thread.h> +#ifdef USE_MPK +# include <mpklib4php.h> +#else # include <nks/synch.h> +#endif #elif defined(GNUPTH) # include <pth.h> #elif defined(PTHREADS) @@ -60,7 +64,11 @@ # define MUTEX_T CRITICAL_SECTION * #elif defined(NETWARE) # define THREAD_T NXThreadId_t +#ifdef USE_MPK +# define MUTEX_T MUTEX +#else # define MUTEX_T NXMutex_t * +#endif #elif defined(GNUPTH) # define THREAD_T pth_t # define MUTEX_T pth_mutex_t * 1.3 +4 -2 TSRM/tsrm_config.nw.h Index: tsrm_config.nw.h =================================================================== RCS file: /cvsroot/php-i18n/TSRM/tsrm_config.nw.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- tsrm_config.nw.h 2 Aug 2002 09:47:43 -0000 1.2 +++ tsrm_config.nw.h 11 Feb 2003 03:09:19 -0000 1.3 @@ -3,7 +3,9 @@ #define HAVE_UTIME 1 -/* Though we have alloca(), this seems to be causing some problem with the stack pointer -- hence not using it */ -/* #define HAVE_ALLOCA 1 */ +/* Though we have alloca(), this seems to be causing some problem + * with the stack pointer. Hence not using it + */ +/*#define HAVE_ALLOCA 1*/ #endif 1.6 +7 -3 TSRM/tsrm_config_common.h Index: tsrm_config_common.h =================================================================== RCS file: /cvsroot/php-i18n/TSRM/tsrm_config_common.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- tsrm_config_common.h 6 Oct 2002 21:18:39 -0000 1.5 +++ tsrm_config_common.h 11 Feb 2003 03:09:19 -0000 1.6 @@ -14,16 +14,20 @@ # include <sys/param.h> #endif +#if HAVE_ALLOCA_H && !defined(_ALLOCA_H) +# include <alloca.h> +#endif + /* AIX requires this to be the first thing in the file. */ #ifndef __GNUC__ -# if HAVE_ALLOCA_H -# include <alloca.h> -# else +# ifndef HAVE_ALLOCA_H # ifdef _AIX #pragma alloca # else # ifndef alloca /* predefined by HP cc +Olibcalls */ +# ifndef NETWARE char *alloca (); +# endif # endif # endif # endif 1.3 +150 -170 TSRM/tsrm_nw.c Index: tsrm_nw.c =================================================================== RCS file: /cvsroot/php-i18n/TSRM/tsrm_nw.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- tsrm_nw.c 2 Aug 2002 09:47:43 -0000 1.2 +++ tsrm_nw.c 11 Feb 2003 03:09:19 -0000 1.3 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2002 The PHP Group | + | Copyright (c) 1997-2003 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -13,10 +13,11 @@ | licen****@php***** so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Venkat Raghavan S <rvenk****@novel*****> | + | Anantha Kesari H Y <hyana****@novel*****> | +----------------------------------------------------------------------+ */ -/* $Id: tsrm_nw.c,v 1.1 2002/05/29 08:41:21 rvenkat Exp $ */ +/* $Id: tsrm_nw.c,v 1.3 2003/01/02 14:29:00 hyanantha Exp $ */ #include <stdlib.h> #include <stdio.h> @@ -39,8 +40,9 @@ #include "mktemp.h" -/* strtok() call in LibC is abending when used in a different address space -- hence using - PHP's version itself for now : Venkat (30/4/02) */ +/* strtok() call in LibC is abending when used in a different address space + * -- hence using PHP's version itself for now + */ #include "tsrm_strtok_r.h" #define tsrm_strtok_r(a,b,c) strtok((a),(b)) @@ -50,211 +52,189 @@ TSRM_API FILE* popen(const char *commandline, const char *type) { - char *command = NULL, *argv[MAX_ARGS] = {'\0'}, **env = NULL; + char *command = NULL, *argv[MAX_ARGS] = {'\0'}, **env = NULL; char *tempName = "sys:/php/temp/phpXXXXXX.tmp"; - char *filePath = NULL; - char *ptr = NULL; - int ptrLen = 0, argc = 0, i = 0, envCount = 0, err = 0; + char *filePath = NULL; + char *ptr = NULL; + int ptrLen = 0, argc = 0, i = 0, envCount = 0, err = 0; FILE *stream = NULL; #if defined(USE_PIPE_OPEN) || defined(USE_MKFIFO) - int pipe_handle; - int mode = O_RDONLY; + int pipe_handle; + int mode = O_RDONLY; #else - NXHandle_t pipe_handle; - NXMode_t mode = NX_O_RDONLY; + NXHandle_t pipe_handle; + NXMode_t mode = NX_O_RDONLY; #endif - NXExecEnvSpec_t envSpec; - NXNameSpec_t nameSpec; - NXVmId_t newVM = 0; - - /* Check for validity of input parameters */ - if (!commandline || !type) - return NULL; - - /* Get temporary file name */ - filePath = mktemp(tempName); -/*consoleprintf ("PHP | popen: file path = %s, mode = %s\n", filePath, type);*/ + NXExecEnvSpec_t envSpec; + NXNameSpec_t nameSpec; + NXVmId_t newVM = 0; + + /* Check for validity of input parameters */ + if (!commandline || !type) + return NULL; + + /* Get temporary file name */ + filePath = mktemp(tempName); if (!filePath) return NULL; - /* Set pipe mode according to type -- for now allow only "r" or "w" */ - if (strcmp(type, "r") == 0) + /* Set pipe mode according to type -- for now allow only "r" or "w" */ + if (strcmp(type, "r") == 0) #if defined(USE_PIPE_OPEN) || defined(USE_MKFIFO) - mode = O_RDONLY; + mode = O_RDONLY; #else - mode = NX_O_RDONLY; + mode = NX_O_RDONLY; #endif - else if (strcmp(type, "w") == 0) + else if (strcmp(type, "w") == 0) #if defined(USE_PIPE_OPEN) || defined(USE_MKFIFO) - mode = O_WRONLY; + mode = O_WRONLY; #else - mode = NX_O_WRONLY; + mode = NX_O_WRONLY; #endif - else - return NULL; + else + return NULL; #ifdef USE_PIPE_OPEN - pipe_handle = pipe_open(filePath, mode); -/*consoleprintf ("PHP | popen: pipe_open() returned %d\n", pipe_handle);*/ - if (pipe_handle == -1) - return NULL; + pipe_handle = pipe_open(filePath, mode); + if (pipe_handle == -1) + return NULL; #elif defined(USE_MKFIFO) - pipe_handle = mkfifo(filePath, mode); -consoleprintf ("PHP | popen: mkfifo() returned %d\n", pipe_handle); - if (pipe_handle == -1) - return NULL; + pipe_handle = mkfifo(filePath, mode); + if (pipe_handle == -1) + return NULL; #else - /* - - NetWare doesn't require first parameter - - Allowing LibC to choose the buffer size for now - */ - err = NXFifoOpen(0, filePath, mode, 0, &pipe_handle); -/*consoleprintf ("PHP | popen: NXFifoOpen() returned %d\n", err);*/ - if (err) - return NULL; + /* - NetWare doesn't require first parameter + * - Allowing LibC to choose the buffer size for now + */ + err = NXFifoOpen(0, filePath, mode, 0, &pipe_handle); + if (err) + return NULL; #endif - /* Copy the environment variables in preparation for the spawn call */ + /* Copy the environment variables in preparation for the spawn call */ + envCount = NXGetEnvCount() + 1; /* add one for NULL */ + env = (char **) NXMemAlloc(sizeof(char *) * envCount, 0); + if (!env) + return NULL; + + err = NXCopyEnv(env, envCount); + if (err) { + NXMemFree (env); + return NULL; + } + + /* Separate commandline string into words */ + ptr = tsrm_strtok_r((char*)commandline, WHITESPACE, NULL); + ptrLen = strlen(ptr); + + command = (char*)malloc(ptrLen + 1); + if (!command) { + NXMemFree (env); + return NULL; + } + + strcpy (command, ptr); + + ptr = tsrm_strtok_r(NULL, WHITESPACE, NULL); + while (ptr && (argc < MAX_ARGS)) { + ptrLen = strlen(ptr); + + argv[argc] = (char*)malloc(ptrLen + 1); + if (!argv[argc]) { + NXMemFree (env); + if (command) + free (command); + + for (i = 0; i < argc; i++) { + if (argv[i]) + free (argv[i]); + } + + return NULL; + } + + strcpy (argv[argc], ptr); + argc++; + ptr = tsrm_strtok_r(NULL, WHITESPACE, NULL); + } + + /* Setup the execution environment and spawn new process */ + envSpec.esFlags = 0; /* Not used */ + envSpec.esArgc = argc; + envSpec.esArgv = (void **) argv; + envSpec.esEnv = (void **) env; + +/* envSpec.esStdin.ssType = */ + envSpec.esStdout.ssType = NX_OBJ_FIFO; + envSpec.esStderr.ssType = NX_OBJ_FILE; - envCount = NXGetEnvCount() + 1; /* add one for NULL */ - env = (char**)NXMemAlloc(sizeof(char*) * envCount, 0); - if (!env) - return NULL; - - err = NXCopyEnv(env, envCount); -consoleprintf ("PHP | popen: NXCopyEnv() returned %d\n", err); - if (err) - { - NXMemFree (env); - return NULL; - } - - /* Separate commandline string into words */ -consoleprintf ("PHP | popen: commandline = %s\n", commandline); - ptr = tsrm_strtok_r((char*)commandline, WHITESPACE, NULL); - ptrLen = strlen(ptr); - - command = (char*)malloc(ptrLen + 1); - if (!command) - { - NXMemFree (env); - return NULL; - } - - strcpy (command, ptr); - - ptr = tsrm_strtok_r(NULL, WHITESPACE, NULL); - while (ptr && (argc < MAX_ARGS)) - { - ptrLen = strlen(ptr); - - argv[argc] = (char*)malloc(ptrLen + 1); - if (!argv[argc]) - { - NXMemFree (env); - - if (command) - free (command); - - for (i = 0; i < argc; i++) - { - if (argv[i]) - free (argv[i]); - } - - return NULL; - } - - strcpy (argv[argc], ptr); - - argc++; - - ptr = tsrm_strtok_r(NULL, WHITESPACE, NULL); - } -consoleprintf ("PHP | popen: commandline string parsed into tokens\n"); - /* Setup the execution environment and spawn new process */ - - envSpec.esFlags = 0; /* Not used */ - envSpec.esArgc = argc; - envSpec.esArgv = (void**)argv; - envSpec.esEnv = (void**)env; - - envSpec.esStdin.ssType = - envSpec.esStdout.ssType = NX_OBJ_FIFO; - envSpec.esStderr.ssType = NX_OBJ_FILE; + /* 'ssHandle' is not a struct/union/class member */ /* - envSpec.esStdin.ssHandle = - envSpec.esStdout.ssHandle = - envSpec.esStderr.ssHandle = -1; + envSpec.esStdin.ssHandle = + envSpec.esStdout.ssHandle = + envSpec.esStderr.ssHandle = -1; */ - envSpec.esStdin.ssPathCtx = - envSpec.esStdout.ssPathCtx = - envSpec.esStderr.ssPathCtx = NULL; + envSpec.esStdin.ssPathCtx = NULL; + envSpec.esStdout.ssPathCtx = NULL; + envSpec.esStderr.ssPathCtx = NULL; #if defined(USE_PIPE_OPEN) || defined(USE_MKFIFO) - if (mode == O_RDONLY) + if (mode == O_RDONLY) { #else - if (mode == NX_O_RDONLY) + if (mode == NX_O_RDONLY) { #endif - { - envSpec.esStdin.ssPath = filePath; - envSpec.esStdout.ssPath = stdout; - } - else /* Write Only */ - { - envSpec.esStdin.ssPath = stdin; - envSpec.esStdout.ssPath = filePath; - } - - envSpec.esStderr.ssPath = stdout; - - nameSpec.ssType = NX_OBJ_FIFO; -/* nameSpec.ssHandle = 0; */ /* Not used */ - nameSpec.ssPathCtx = NULL; /* Not used */ - nameSpec.ssPath = argv[0]; -consoleprintf ("PHP | popen: environment setup\n"); - err = NXVmSpawn(&nameSpec, &envSpec, 0, &newVM); -consoleprintf ("PHP | popen: NXVmSpawn() returned %d\n", err); - if (!err) - /* Get file pointer corresponding to the pipe (file) opened */ - stream = fdopen(pipe_handle, type); + envSpec.esStdin.ssPath = filePath; + envSpec.esStdout.ssPath = stdout; + } else { /* Write Only */ + envSpec.esStdin.ssPath = stdin; + envSpec.esStdout.ssPath = filePath; + } + + envSpec.esStderr.ssPath = stdout; + + nameSpec.ssType = NX_OBJ_FIFO; +/* nameSpec.ssHandle = 0; */ /* 'ssHandle' is not a struct/union/class member */ + nameSpec.ssPathCtx = NULL; /* Not used */ + nameSpec.ssPath = argv[0]; + err = NXVmSpawn(&nameSpec, &envSpec, 0, &newVM); + if (!err) + /* Get file pointer corresponding to the pipe (file) opened */ + stream = fdopen(pipe_handle, type); + + /* Clean-up */ + if (env) + NXMemFree (env); - /* Clean-up */ - - if (env) - NXMemFree (env); - - if (pipe_handle) + if (pipe_handle) #if defined(USE_PIPE_OPEN) || defined(USE_MKFIFO) - close(pipe_handle); + close(pipe_handle); #else - NXClose(pipe_handle); + NXClose(pipe_handle); #endif - if (command) - free (command); + if (command) + free (command); - for (i = 0; i < argc; i++) - { - if (argv[i]) - free (argv[i]); - } -consoleprintf ("PHP | popen: all clean-up done, returning...\n"); - return stream; + for (i = 0; i < argc; i++) { + if (argv[i]) + free (argv[i]); + } + + return stream; } TSRM_API int pclose(FILE* stream) { - int err = 0; - NXHandle_t fd = 0; + int err = 0; + NXHandle_t fd = 0; - /* Get the process associated with this pipe (file) handle and terminate it */ - fd = fileno(stream); - NXClose (fd); + /* Get the process associated with this pipe (file) handle and terminate it */ + fd = fileno(stream); + NXClose (fd); - err = fclose(stream); + err = fclose(stream); - return err; + return err; } -#endif +#endif /* NETWARE */ 1.3 +2 -1 TSRM/tsrm_nw.h Index: tsrm_nw.h =================================================================== RCS file: /cvsroot/php-i18n/TSRM/tsrm_nw.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- tsrm_nw.h 2 Aug 2002 09:47:43 -0000 1.2 +++ tsrm_nw.h 11 Feb 2003 03:09:19 -0000 1.3 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2002 The PHP Group | + | Copyright (c) 1997-2003 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -13,6 +13,7 @@ | licen****@php***** so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Venkat Raghavan S <rvenk****@novel*****> | + | Anantha Kesari H Y <hyana****@novel*****> | +----------------------------------------------------------------------+ */ 1.6 +41 -77 TSRM/tsrm_virtual_cwd.c Index: tsrm_virtual_cwd.c =================================================================== RCS file: /cvsroot/php-i18n/TSRM/tsrm_virtual_cwd.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- tsrm_virtual_cwd.c 6 Oct 2002 21:18:39 -0000 1.5 +++ tsrm_virtual_cwd.c 11 Feb 2003 03:09:19 -0000 1.6 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2002 The PHP Group | + | Copyright (c) 1997-2003 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: tsrm_virtual_cwd.c,v 1.32 2002/10/05 11:26:17 dreid Exp $ */ +/* $Id: tsrm_virtual_cwd.c,v 1.46 2003/02/09 03:49:42 shane Exp $ */ #include <sys/types.h> #include <sys/stat.h> @@ -41,7 +41,7 @@ #include "tsrm_nw.h" #endif -#ifdef __BEOS__ +#ifndef HAVE_REALPATH #define realpath(x,y) strcpy(y,x) #endif @@ -49,7 +49,7 @@ #include "TSRM.h" -/* Only need mutex for popen() in Windows and NetWare, because it doesn't chdir() on UNIX */ +/* Only need mutex for popen() in Windows and NetWare because it doesn't chdir() on UNIX */ #if (defined(TSRM_WIN32) || defined(NETWARE)) && defined(ZTS) MUTEX_T cwd_mutex; #endif @@ -210,7 +210,7 @@ cwd_globals_ctor(&cwd_globals TSRMLS_CC); #endif -#if defined(TSRM_WIN32) && defined(ZTS) +#if (defined(TSRM_WIN32) || defined(NETWARE)) && defined(ZTS) cwd_mutex = tsrm_mutex_alloc(); #endif } @@ -220,7 +220,7 @@ #ifndef ZTS cwd_globals_dtor(&cwd_globals TSRMLS_CC); #endif -#if defined(TSRM_WIN32) && defined(ZTS) +#if (defined(TSRM_WIN32) || defined(NETWARE)) && defined(ZTS) tsrm_mutex_free(cwd_mutex); #endif @@ -284,7 +284,7 @@ /* Resolve path relatively to state and put the real path into state */ /* returns 0 for ok, 1 for error */ -CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path) +CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path, int use_realpath) { int path_length = strlen(path); char *ptr, *path_copy; @@ -304,7 +304,7 @@ #if !defined(TSRM_WIN32) && !defined(NETWARE) if (IS_ABSOLUTE_PATH(path, path_length)) { - if (realpath(path, resolved_path)) { + if (use_realpath && realpath(path, resolved_path)) { path = resolved_path; path_length = strlen(path); } @@ -322,7 +322,7 @@ memcpy(ptr, path, path_length); ptr += path_length; *ptr = '\0'; - if (realpath(tmp, resolved_path)) { + if (use_realpath && realpath(tmp, resolved_path)) { path = resolved_path; path_length = strlen(path); } @@ -337,17 +337,9 @@ fprintf(stderr,"cwd = %s path = %s\n", state->cwd, path); #endif if (IS_ABSOLUTE_PATH(path_copy, path_length)) { -/* COPY_WHEN_ABSOLUTE needs to account for volume name that is unique to NetWare absolute paths */ -#ifndef NETWARE - copy_amount = COPY_WHEN_ABSOLUTE; -#else copy_amount = COPY_WHEN_ABSOLUTE(path_copy); -#endif is_absolute = 1; #ifdef TSRM_WIN32 - } else if (IS_UNC_PATH(path_copy, path_length)) { - copy_amount = 2; - is_absolute = 1; } else if (IS_SLASH(path_copy[0])) { copy_amount = 2; #endif @@ -415,12 +407,7 @@ ptr = tsrm_strtok_r(NULL, TOKENIZER_STRING, &tok); } -/* COPY_WHEN_ABSOLUTE needs to account for volume name that is unique to NetWare absolute paths */ -#ifndef NETWARE - if (state->cwd_length == COPY_WHEN_ABSOLUTE) { -#else if (state->cwd_length == COPY_WHEN_ABSOLUTE(state->cwd)) { -#endif state->cwd = (char *) realloc(state->cwd, state->cwd_length+1+1); state->cwd[state->cwd_length] = DEFAULT_SLASH; state->cwd[state->cwd_length+1] = '\0'; @@ -449,7 +436,7 @@ CWD_API int virtual_chdir(const char *path TSRMLS_DC) { - return virtual_file_ex(&CWDG(cwd), path, php_is_dir_ok)?-1:0; + return virtual_file_ex(&CWDG(cwd), path, php_is_dir_ok, 1)?-1:0; } CWD_API int virtual_chdir_file(const char *path, int (*p_chdir)(const char *path TSRMLS_DC) TSRMLS_DC) @@ -470,12 +457,7 @@ return -1; } -/* COPY_WHEN_ABSOLUTE needs to account for volume name that is unique to NetWare absolute paths */ -#ifndef NETWARE - if (length == COPY_WHEN_ABSOLUTE && IS_ABSOLUTE_PATH(path, length+1)) { /* Also use trailing slash if this is absolute */ -#else if (length == COPY_WHEN_ABSOLUTE(path) && IS_ABSOLUTE_PATH(path, length+1)) { /* Also use trailing slash if this is absolute */ -#endif length++; } temp = (char *) tsrm_do_alloca(length+1); @@ -492,19 +474,23 @@ CWD_API char *virtual_realpath(const char *path, char *real_path TSRMLS_DC) { cwd_state new_state; - int retval; + char *retval; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - retval = virtual_file_ex(&new_state, path, NULL); - if (!retval) { + if (virtual_file_ex(&new_state, path, NULL, 1)==0) { int len = new_state.cwd_length>MAXPATHLEN-1?MAXPATHLEN-1:new_state.cwd_length; + memcpy(real_path, new_state.cwd, len); real_path[len] = '\0'; - return real_path; + retval = real_path; + } else { + retval = NULL; } - return NULL; + CWD_STATE_FREE(&new_state); + + return retval; } CWD_API int virtual_filepath_ex(const char *path, char **filepath, verify_path_func verify_path TSRMLS_DC) @@ -513,7 +499,7 @@ int retval; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - retval = virtual_file_ex(&new_state, path, verify_path); + retval = virtual_file_ex(&new_state, path, verify_path, 1); *filepath = new_state.cwd; @@ -536,7 +522,7 @@ } CWD_STATE_COPY(&new_state, &CWDG(cwd)); - virtual_file_ex(&new_state, path, NULL); + virtual_file_ex(&new_state, path, NULL, 1); f = fopen(new_state.cwd, mode); @@ -544,22 +530,24 @@ return f; } -#if !defined(TSRM_WIN32) CWD_API int virtual_access(const char *pathname, int mode TSRMLS_DC) { cwd_state new_state; int ret; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - virtual_file_ex(&new_state, pathname, NULL); + virtual_file_ex(&new_state, pathname, NULL, 1); +#if defined(TSRM_WIN32) + ret = tsrm_win32_access(new_state.cwd, mode); +#else ret = access(new_state.cwd, mode); +#endif CWD_STATE_FREE(&new_state); return ret; } -#endif #if HAVE_UTIME @@ -569,7 +557,7 @@ int ret; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - virtual_file_ex(&new_state, filename, NULL); + virtual_file_ex(&new_state, filename, NULL, 0); ret = utime(new_state.cwd, buf); @@ -584,7 +572,7 @@ int ret; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - virtual_file_ex(&new_state, filename, NULL); + virtual_file_ex(&new_state, filename, NULL, 1); ret = chmod(new_state.cwd, mode); @@ -599,7 +587,7 @@ int ret; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - virtual_file_ex(&new_state, filename, NULL); + virtual_file_ex(&new_state, filename, NULL, 0); ret = chown(new_state.cwd, owner, group); @@ -614,7 +602,7 @@ int f; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - virtual_file_ex(&new_state, path, NULL); + virtual_file_ex(&new_state, path, NULL, 1); if (flags & O_CREAT) { mode_t mode; @@ -638,7 +626,7 @@ int f; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - virtual_file_ex(&new_state, path, NULL); + virtual_file_ex(&new_state, path, NULL, 1); f = creat(new_state.cwd, mode); @@ -653,11 +641,11 @@ int retval; CWD_STATE_COPY(&old_state, &CWDG(cwd)); - virtual_file_ex(&old_state, oldname, NULL); + virtual_file_ex(&old_state, oldname, NULL, 0); oldname = old_state.cwd; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - virtual_file_ex(&new_state, newname, NULL); + virtual_file_ex(&new_state, newname, NULL, 0); newname = new_state.cwd; retval = rename(oldname, newname); @@ -675,7 +663,7 @@ int retval; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - virtual_file_ex(&new_state, path, NULL); + virtual_file_ex(&new_state, path, NULL, 1); retval = stat(new_state.cwd, buf); @@ -689,7 +677,7 @@ int retval; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - virtual_file_ex(&new_state, path, NULL); + virtual_file_ex(&new_state, path, NULL, 1); retval = stat(new_state.cwd, (struct stat*)buf); @@ -705,7 +693,7 @@ int retval; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - virtual_file_ex(&new_state, path, NULL); + virtual_file_ex(&new_state, path, NULL, 0); retval = lstat(new_state.cwd, buf); @@ -720,7 +708,7 @@ int retval; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - virtual_file_ex(&new_state, path, NULL); + virtual_file_ex(&new_state, path, NULL, 0); retval = unlink(new_state.cwd); @@ -734,7 +722,7 @@ int retval; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - virtual_file_ex(&new_state, pathname, NULL); + virtual_file_ex(&new_state, pathname, NULL, 1); #ifdef TSRM_WIN32 retval = mkdir(new_state.cwd); @@ -751,7 +739,7 @@ int retval; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - virtual_file_ex(&new_state, pathname, NULL); + virtual_file_ex(&new_state, pathname, NULL, 0); retval = rmdir(new_state.cwd); @@ -769,7 +757,7 @@ DIR *retval; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - virtual_file_ex(&new_state, pathname, NULL); + virtual_file_ex(&new_state, pathname, NULL, 1); retval = opendir(new_state.cwd); @@ -779,33 +767,9 @@ #ifdef TSRM_WIN32 -/* 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 TSRMLS_DC) { - char prev_cwd[MAXPATHLEN]; - char *getcwd_result; - FILE *retval; - - getcwd_result = getcwd(prev_cwd, MAXPATHLEN); - if (!getcwd_result) { - return NULL; - } - -#ifdef ZTS - tsrm_mutex_lock(cwd_mutex); -#endif - - chdir(CWDG(cwd).cwd); - retval = popen(command, type); - chdir(prev_cwd); - -#ifdef ZTS - tsrm_mutex_unlock(cwd_mutex); -#endif - - return retval; + return popen_ex(command, type, CWDG(cwd).cwd, NULL); } #elif defined(NETWARE) 1.6 +31 -11 TSRM/tsrm_virtual_cwd.h Index: tsrm_virtual_cwd.h =================================================================== RCS file: /cvsroot/php-i18n/TSRM/tsrm_virtual_cwd.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- tsrm_virtual_cwd.h 6 Oct 2002 21:18:39 -0000 1.5 +++ tsrm_virtual_cwd.h 11 Feb 2003 03:09:19 -0000 1.6 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2002 The PHP Group | + | Copyright (c) 1997-2003 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: tsrm_virtual_cwd.h,v 1.20 2002/10/04 01:04:00 sas Exp $ */ +/* $Id: tsrm_virtual_cwd.h,v 1.34 2003/02/09 03:49:42 shane Exp $ */ #ifndef VIRTUAL_CWD_H #define VIRTUAL_CWD_H @@ -52,11 +52,14 @@ #define IS_SLASH(c) ((c) == '/' || (c) == '\\') #define IS_SLASH_P(c) (*(c) == '/' || \ (*(c) == '\\' && !IsDBCSLeadByte(*(c-1)))) -#define COPY_WHEN_ABSOLUTE 2 -#define IS_ABSOLUTE_PATH(path, len) \ - (len >= 2 && isalpha(path[0]) && path[1] == ':') + +/* COPY_WHEN_ABSOLUTE is 2 under Win32 because by chance both regular absolute paths + in the file system and UNC paths need copying of two characters */ +#define COPY_WHEN_ABSOLUTE(path) 2 #define IS_UNC_PATH(path, len) \ (len >= 2 && IS_SLASH(path[0]) && IS_SLASH(path[1])) +#define IS_ABSOLUTE_PATH(path, len) \ + (len >= 2 && ((isalpha(path[0]) && path[1] == ':') || IS_UNC_PATH(path, len))) #elif defined(NETWARE) #ifdef HAVE_DIRENT_H @@ -66,6 +69,7 @@ #define DEFAULT_SLASH '/' #define DEFAULT_DIR_SEPARATOR ';' #define IS_SLASH(c) ((c) == '/' || (c) == '\\') +#define IS_SLASH_P(c) IS_SLASH(*(c)) #define COPY_WHEN_ABSOLUTE(path) \ (strchr(path, ':') - path + 1) /* Take the volume name which ends with a colon */ #define IS_ABSOLUTE_PATH(path, len) \ @@ -91,7 +95,7 @@ #ifndef COPY_WHEN_ABSOLUTE -#define COPY_WHEN_ABSOLUTE 0 +#define COPY_WHEN_ABSOLUTE(path) 0 #endif #ifndef IS_ABSOLUTE_PATH @@ -146,9 +150,21 @@ CWD_API int virtual_rmdir(const char *pathname TSRMLS_DC); CWD_API DIR *virtual_opendir(const char *pathname TSRMLS_DC); CWD_API FILE *virtual_popen(const char *command, const char *type TSRMLS_DC); - -#if !defined(TSRM_WIN32) CWD_API int virtual_access(const char *pathname, int mode TSRMLS_DC); +#if defined(TSRM_WIN32) +/* these are not defined in win32 headers */ +#ifndef W_OK +#define W_OK 0x02 +#endif +#ifndef R_OK +#define R_OK 0x04 +#endif +#ifndef X_OK +#define X_OK 0x01 +#endif +#ifndef F_OK +#define F_OK 0x00 +#endif #endif #if HAVE_UTIME @@ -159,7 +175,7 @@ CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group TSRMLS_DC); #endif -CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path); +CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path, int use_realpath); typedef struct _virtual_cwd_globals { cwd_state cwd; @@ -191,7 +207,7 @@ #define VCWD_RENAME(oldname, newname) virtual_rename(oldname, newname TSRMLS_CC) #define VCWD_STAT(path, buff) virtual_stat(path, buff TSRMLS_CC) #if !defined(TSRM_WIN32) && !defined(NETWARE) -#define VCWD_LSTAT(path, buff) virtual_stat(path, buff TSRMLS_CC) +#define VCWD_LSTAT(path, buff) virtual_lstat(path, buff TSRMLS_CC) #else #define VCWD_LSTAT(path, buff) virtual_lstat(path, buff TSRMLS_CC) #endif @@ -227,9 +243,13 @@ #define VCWD_RMDIR(pathname) rmdir(pathname) #define VCWD_OPENDIR(pathname) opendir(pathname) #define VCWD_POPEN(command, type) popen(command, type) +#if defined(TSRM_WIN32) +#define VCWD_ACCESS(pathname, mode) tsrm_win32_access(pathname, mode) +#else #define VCWD_ACCESS(pathname, mode) access(pathname, mode) +#endif -#if !defined(TSRM_WIN32) && !defined(NETWARE) +#ifdef HAVE_REALPATH #define VCWD_REALPATH(path, real_path) realpath(path, real_path) #else #define VCWD_REALPATH(path, real_path) strcpy(real_path, path) 1.4 +21 -4 TSRM/tsrm_win32.c Index: tsrm_win32.c =================================================================== RCS file: /cvsroot/php-i18n/TSRM/tsrm_win32.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- tsrm_win32.c 6 Oct 2002 21:18:39 -0000 1.3 +++ tsrm_win32.c 11 Feb 2003 03:09:19 -0000 1.4 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2002 The PHP Group | + | Copyright (c) 1997-2003 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: tsrm_win32.c,v 1.13 2002/08/07 14:47:05 phanto Exp $ */ +/* $Id: tsrm_win32.c,v 1.17 2003/02/09 12:10:28 derick Exp $ */ #include <stdio.h> #include <fcntl.h> @@ -81,6 +81,18 @@ #endif } +TSRM_API int tsrm_win32_access(const char *pathname, int mode) +{ + SHFILEINFO sfi; + if (mode == 1 /*X_OK*/) { + return access(pathname, 0) == 0 && + SHGetFileInfo(pathname, 0, &sfi, sizeof(SHFILEINFO), SHGFI_EXETYPE) != 0 ? 0 : -1; + } else { + return access(pathname, mode); + } +} + + static process_pair *process_get(FILE *stream TSRMLS_DC) { process_pair *ptr; @@ -149,6 +161,11 @@ TSRM_API FILE *popen(const char *command, const char *type) { + return popen_ex(command, type, NULL, NULL); +} + +TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, char *env) +{ FILE *stream = NULL; int fno, str_len = strlen(type), read, mode; STARTUPINFO startup; @@ -190,7 +207,7 @@ cmd = (char*)malloc(strlen(command)+strlen(TWG(comspec))+sizeof(" /c ")); sprintf(cmd, "%s /c %s", TWG(comspec), command); - if (!CreateProcess(NULL, cmd, &security, &security, security.bInheritHandle, NORMAL_PRIORITY_CLASS, NULL, NULL, &startup, &process)) { + if (!CreateProcess(NULL, cmd, &security, &security, security.bInheritHandle, NORMAL_PRIORITY_CLASS, env, cwd, &startup, &process)) { return NULL; } free(cmd); @@ -354,4 +371,4 @@ return -1; } } -#endif \ No newline at end of file +#endif 1.4 +4 -2 TSRM/tsrm_win32.h Index: tsrm_win32.h =================================================================== RCS file: /cvsroot/php-i18n/TSRM/tsrm_win32.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- tsrm_win32.h 6 Oct 2002 21:18:39 -0000 1.3 +++ tsrm_win32.h 11 Feb 2003 03:09:19 -0000 1.4 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2002 The PHP Group | + | Copyright (c) 1997-2003 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: tsrm_win32.h,v 1.8 2002/08/07 14:47:05 phanto Exp $ */ +/* $Id: tsrm_win32.h,v 1.11 2003/02/09 03:49:42 shane Exp $ */ #ifndef TSRM_WIN32_H #define TSRM_WIN32_H @@ -92,8 +92,10 @@ TSRM_API void tsrm_win32_startup(void); TSRM_API void tsrm_win32_shutdown(void); +TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, char *env); TSRM_API FILE *popen(const char *command, const char *type); TSRM_API int pclose(FILE *stream); +TSRM_API int tsrm_win32_access(const char *pathname, int mode); TSRM_API int shmget(int key, int size, int flags); TSRM_API void *shmat(int key, const void *shmaddr, int flags);