diff options
author | Anantha Kesari H Y <hyanantha@php.net> | 2003-01-02 14:29:00 +0000 |
---|---|---|
committer | Anantha Kesari H Y <hyanantha@php.net> | 2003-01-02 14:29:00 +0000 |
commit | 455257974bb819cd1a43b98084b6b360eed6235a (patch) | |
tree | 6d84f7dc82be57a35a73add5ff135a813d820be8 | |
parent | 895b5fc2b68a613f840f2dbae81f049ebb2065cb (diff) | |
download | php-git-455257974bb819cd1a43b98084b6b360eed6235a.tar.gz |
NetWare related changes/modifications.
-rw-r--r-- | TSRM/TSRM.c | 44 | ||||
-rw-r--r-- | TSRM/TSRM.h | 8 | ||||
-rw-r--r-- | TSRM/tsrm_config.nw.h | 6 | ||||
-rw-r--r-- | TSRM/tsrm_nw.c | 316 | ||||
-rw-r--r-- | TSRM/tsrm_nw.h | 1 | ||||
-rw-r--r-- | TSRM/tsrm_virtual_cwd.c | 6 | ||||
-rw-r--r-- | TSRM/tsrm_virtual_cwd.h | 2 |
7 files changed, 205 insertions, 178 deletions
diff --git a/TSRM/TSRM.c b/TSRM/TSRM.c index 7f6ea1f232..56b67f08d9 100644 --- a/TSRM/TSRM.c +++ b/TSRM/TSRM.c @@ -290,6 +290,15 @@ TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id) 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 +361,9 @@ TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id) * 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 +431,12 @@ TSRM_API THREAD_T tsrm_thread_id(void) #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 +458,23 @@ TSRM_API MUTEX_T tsrm_mutex_alloc(void) { 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); @@ -482,7 +506,11 @@ TSRM_API void tsrm_mutex_free(MUTEX_T mutexp) #ifdef TSRM_WIN32 DeleteCriticalSection(mutexp); #elif defined(NETWARE) +#ifdef USE_MPK + kMutexFree(mutexp); +#else NXMutexFree(mutexp); +#endif #elif defined(GNUPTH) free(mutexp); #elif defined(PTHREADS) @@ -513,7 +541,11 @@ TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp) 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 +572,11 @@ TSRM_API int tsrm_mutex_unlock(MUTEX_T mutexp) 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) diff --git a/TSRM/TSRM.h b/TSRM/TSRM.h index a80500d6db..14c5873179 100644 --- a/TSRM/TSRM.h +++ b/TSRM/TSRM.h @@ -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 @@ typedef int ts_rsrc_id; # 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 * diff --git a/TSRM/tsrm_config.nw.h b/TSRM/tsrm_config.nw.h index 0681852c7d..14fcc19ab2 100644 --- a/TSRM/tsrm_config.nw.h +++ b/TSRM/tsrm_config.nw.h @@ -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 diff --git a/TSRM/tsrm_nw.c b/TSRM/tsrm_nw.c index 3559b783a8..2467c0fcd8 100644 --- a/TSRM/tsrm_nw.c +++ b/TSRM/tsrm_nw.c @@ -13,6 +13,7 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Venkat Raghavan S <rvenkat@novell.com> | + | Anantha Kesari H Y <hyanantha@novell.com> | +----------------------------------------------------------------------+ */ @@ -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; + NXExecEnvSpec_t envSpec; + NXNameSpec_t nameSpec; + NXVmId_t newVM = 0; - /* Check for validity of input parameters */ - if (!commandline || !type) - return NULL; + /* 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);*/ + /* 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 */ - - 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; + /* 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; + + /* '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); - - /* Clean-up */ - - if (env) - NXMemFree (env); - - if (pipe_handle) + 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); + + 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 */ diff --git a/TSRM/tsrm_nw.h b/TSRM/tsrm_nw.h index e5ba62b8aa..5c5357ef95 100644 --- a/TSRM/tsrm_nw.h +++ b/TSRM/tsrm_nw.h @@ -13,6 +13,7 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Venkat Raghavan S <rvenkat@novell.com> | + | Anantha Kesari H Y <hyanantha@novell.com> | +----------------------------------------------------------------------+ */ diff --git a/TSRM/tsrm_virtual_cwd.c b/TSRM/tsrm_virtual_cwd.c index 2bf7c9369a..4706ba102c 100644 --- a/TSRM/tsrm_virtual_cwd.c +++ b/TSRM/tsrm_virtual_cwd.c @@ -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_API void virtual_cwd_startup(void) 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 @@ CWD_API void virtual_cwd_shutdown(void) #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 diff --git a/TSRM/tsrm_virtual_cwd.h b/TSRM/tsrm_virtual_cwd.h index e9168f7033..d77e8f8166 100644 --- a/TSRM/tsrm_virtual_cwd.h +++ b/TSRM/tsrm_virtual_cwd.h @@ -69,7 +69,7 @@ typedef unsigned short mode_t; #define DEFAULT_SLASH '/' #define DEFAULT_DIR_SEPARATOR ';' #define IS_SLASH(c) ((c) == '/' || (c) == '\\') -#define IS_SLASH_P(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) \ |