diff options
author | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:35:28 -0400 |
---|---|---|
committer | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:35:28 -0400 |
commit | ba50031707469046407a35b77a3cd81351e951b3 (patch) | |
tree | 5c03e723bdbfabae09d41a3ab1253dff41eeed4a /TSRM | |
parent | 0a36161e13484a99ccf69bb38f206462d27cc6d6 (diff) | |
download | php-ba50031707469046407a35b77a3cd81351e951b3.tar.gz |
Imported Upstream version 5.1.5upstream/5.1.5
Diffstat (limited to 'TSRM')
-rw-r--r-- | TSRM/TSRM.c | 46 | ||||
-rw-r--r-- | TSRM/TSRM.h | 3 | ||||
-rw-r--r-- | TSRM/tsrm_virtual_cwd.c | 58 | ||||
-rw-r--r-- | TSRM/tsrm_virtual_cwd.h | 34 |
4 files changed, 96 insertions, 45 deletions
diff --git a/TSRM/TSRM.c b/TSRM/TSRM.c index c07d60668..8acf0698a 100644 --- a/TSRM/TSRM.c +++ b/TSRM/TSRM.c @@ -480,6 +480,52 @@ void ts_free_thread(void) } +/* frees all resources allocated for all threads except current */ +void ts_free_worker_threads(void) +{ + tsrm_tls_entry *thread_resources; + int i; + THREAD_T thread_id = tsrm_thread_id(); + int hash_value; + tsrm_tls_entry *last=NULL; + + tsrm_mutex_lock(tsmm_mutex); + hash_value = THREAD_HASH_OF(thread_id, tsrm_tls_table_size); + thread_resources = tsrm_tls_table[hash_value]; + + while (thread_resources) { + if (thread_resources->thread_id != thread_id) { + for (i=0; i<thread_resources->count; i++) { + if (resource_types_table[i].dtor) { + resource_types_table[i].dtor(thread_resources->storage[i], &thread_resources->storage); + } + } + for (i=0; i<thread_resources->count; i++) { + free(thread_resources->storage[i]); + } + free(thread_resources->storage); + if (last) { + last->next = thread_resources->next; + } else { + tsrm_tls_table[hash_value] = thread_resources->next; + } + free(thread_resources); + if (last) { + thread_resources = last->next; + } else { + thread_resources = tsrm_tls_table[hash_value]; + } + } else { + if (thread_resources->next) { + last = thread_resources; + } + thread_resources = thread_resources->next; + } + } + tsrm_mutex_unlock(tsmm_mutex); +} + + /* deallocates all occurrences of a given id */ void ts_free_id(ts_rsrc_id id) { diff --git a/TSRM/TSRM.h b/TSRM/TSRM.h index 056089aa9..2eecd52b6 100644 --- a/TSRM/TSRM.h +++ b/TSRM/TSRM.h @@ -106,6 +106,9 @@ TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id); /* frees all resources allocated for the current thread */ TSRM_API void ts_free_thread(void); +/* frees all resources allocated for all threads except current */ +void ts_free_worker_threads(void); + /* deallocates all occurrences of a given id */ TSRM_API void ts_free_id(ts_rsrc_id id); diff --git a/TSRM/tsrm_virtual_cwd.c b/TSRM/tsrm_virtual_cwd.c index 03f847c2a..3b4f1c127 100644 --- a/TSRM/tsrm_virtual_cwd.c +++ b/TSRM/tsrm_virtual_cwd.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: tsrm_virtual_cwd.c,v 1.74.2.4 2006/01/01 12:50:00 sniper Exp $ */ +/* $Id: tsrm_virtual_cwd.c,v 1.74.2.9 2006/03/05 18:57:54 derick Exp $ */ #include <sys/types.h> #include <sys/stat.h> @@ -163,18 +163,15 @@ static int php_is_file_ok(const cwd_state *state) static void cwd_globals_ctor(virtual_cwd_globals *cwd_globals TSRMLS_DC) { CWD_STATE_COPY(&cwd_globals->cwd, &main_cwd_state); -#ifdef REALPATH_CACHE cwd_globals->realpath_cache_size = 0; cwd_globals->realpath_cache_size_limit = REALPATH_CACHE_SIZE; cwd_globals->realpath_cache_ttl = REALPATH_CACHE_TTL; memset(cwd_globals->realpath_cache, 0, sizeof(cwd_globals->realpath_cache)); -#endif } static void cwd_globals_dtor(virtual_cwd_globals *cwd_globals TSRMLS_DC) { CWD_STATE_FREE(&cwd_globals->cwd); -#ifdef REALPATH_CACHE { int i; @@ -187,7 +184,6 @@ static void cwd_globals_dtor(virtual_cwd_globals *cwd_globals TSRMLS_DC) } } } -#endif } static char *tsrm_strndup(const char *s, size_t length) @@ -308,7 +304,6 @@ CWD_API char *virtual_getcwd(char *buf, size_t size TSRMLS_DC) return buf; } -#ifdef REALPATH_CACHE static inline unsigned long realpath_cache_key(const char *path, int path_len) { register unsigned long h; @@ -352,19 +347,18 @@ static inline realpath_cache_bucket* realpath_cache_find(const char *path, int p while (*bucket != NULL) { if (CWDG(realpath_cache_ttl) && (*bucket)->expires < t) { realpath_cache_bucket *r = *bucket; - *bucket = (*bucket)->next; - CWDG(realpath_cache_size) -= sizeof(realpath_cache_bucket) + r->path_len + 1 + r->realpath_len + 1; - free(r); + *bucket = (*bucket)->next; + CWDG(realpath_cache_size) -= sizeof(realpath_cache_bucket) + r->path_len + 1 + r->realpath_len + 1; + free(r); } else if (key == (*bucket)->key && path_len == (*bucket)->path_len && memcmp(path, (*bucket)->path, path_len) == 0) { return *bucket; } else { - *bucket = (*bucket)->next; + bucket = &(*bucket)->next; } } return NULL; } -#endif /* Resolve path relatively to state and put the real path into state */ @@ -385,20 +379,17 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func #else char *new_path; #endif -#ifdef REALPATH_CACHE char orig_path[MAXPATHLEN]; - int orig_path_len; + int orig_path_len = 0; realpath_cache_bucket *bucket; - time_t t; + time_t t = 0; TSRMLS_FETCH(); -#endif if (path_length == 0) return (0); if (path_length >= MAXPATHLEN) return (1); -#ifdef REALPATH_CACHE if (use_realpath && CWDG(realpath_cache_size_limit)) { if (IS_ABSOLUTE_PATH(path, path_length) || (state->cwd_length < 1)) { memcpy(orig_path, path, path_length+1); @@ -430,7 +421,6 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func } } } -#endif #if !defined(TSRM_WIN32) && !defined(NETWARE) /* cwd_length can be 0 when getcwd() fails. * This can happen under solaris when a dir does not have read permissions @@ -609,11 +599,9 @@ php_failed_getlongpath: #endif free(free_path); -#ifdef REALPATH_CACHE if (use_realpath && CWDG(realpath_cache_size_limit)) { realpath_cache_add(orig_path, orig_path_len, state->cwd, state->cwd_length, t TSRMLS_CC); } -#endif if (verify_path && verify_path(state)) { CWD_STATE_FREE(state); @@ -777,7 +765,7 @@ CWD_API int virtual_chmod(const char *filename, mode_t mode TSRMLS_DC) } #if !defined(TSRM_WIN32) && !defined(NETWARE) -CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group TSRMLS_DC) +CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group, int link TSRMLS_DC) { cwd_state new_state; int ret; @@ -785,7 +773,15 @@ CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group TSRMLS_ CWD_STATE_COPY(&new_state, &CWDG(cwd)); virtual_file_ex(&new_state, filename, NULL, 0); - ret = chown(new_state.cwd, owner, group); + if (link) { +#if HAVE_LCHOWN + ret = lchown(new_state.cwd, owner, group); +#else + ret = -1; +#endif + } else { + ret = chown(new_state.cwd, owner, group); + } CWD_STATE_FREE(&new_state); return ret; @@ -1047,6 +1043,26 @@ CWD_API FILE *virtual_popen(const char *command, const char *type TSRMLS_DC) #endif +/* On AIX & Tru64 when a file does not exist realpath() returns + * NULL, and sets errno to ENOENT. Unlike in other libc implementations + * the destination is not filled and remains undefined. Therefor, we + * must populate it manually using strcpy as done on systems with no + * realpath() function. + */ +#if defined(__osf__) || defined(_AIX) +char *php_realpath_hack(char *src, char *dest) +{ + char *ret; + + if ((ret = realpath(src, dest)) == NULL && errno == ENOENT) { + return strcpy(dest, src); + } else { + return ret; + } +} +#endif + + /* * Local variables: diff --git a/TSRM/tsrm_virtual_cwd.h b/TSRM/tsrm_virtual_cwd.h index 1fc54d26e..753ec0207 100644 --- a/TSRM/tsrm_virtual_cwd.h +++ b/TSRM/tsrm_virtual_cwd.h @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: tsrm_virtual_cwd.h,v 1.48.2.1 2006/01/01 12:50:00 sniper Exp $ */ +/* $Id: tsrm_virtual_cwd.h,v 1.48.2.5 2006/04/10 11:56:18 sniper Exp $ */ #ifndef VIRTUAL_CWD_H #define VIRTUAL_CWD_H @@ -166,23 +166,8 @@ CWD_API int virtual_access(const char *pathname, int mode TSRMLS_DC); #endif #endif -/* On AIX & Tru64 when a file does not exist realpath() returns - * NULL, and sets errno to ENOENT. Unlike in other libc implementations - * the destination is not filled and remains undefined. Therefor, we - * must populate it manually using strcpy as done on systems with no - * realpath() function. - */ #if defined(__osf__) || defined(_AIX) -static char *php_realpath_hack(char *src, char *dest) -{ - char *ret; - - if ((ret = realpath(src, dest)) == NULL && errno == ENOENT) { - return strcpy(dest, src); - } else { - return ret; - } -} +char *php_realpath_hack(char *src, char *dest); #endif #if HAVE_UTIME @@ -190,16 +175,14 @@ CWD_API int virtual_utime(const char *filename, struct utimbuf *buf TSRMLS_DC); #endif CWD_API int virtual_chmod(const char *filename, mode_t mode TSRMLS_DC); #if !defined(TSRM_WIN32) && !defined(NETWARE) -CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group TSRMLS_DC); +CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group, int link TSRMLS_DC); #endif CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path, int use_realpath); -#define REALPATH_CACHE #define REALPATH_CACHE_TTL (2*60) /* 2 minutes */ #define REALPATH_CACHE_SIZE 0 /* disabled while php.ini isn't loaded */ -#ifdef REALPATH_CACHE typedef struct _realpath_cache_bucket { unsigned long key; char *path; @@ -209,16 +192,13 @@ typedef struct _realpath_cache_bucket { time_t expires; struct _realpath_cache_bucket *next; } realpath_cache_bucket; -#endif typedef struct _virtual_cwd_globals { cwd_state cwd; -#ifdef REALPATH_CACHE long realpath_cache_size; long realpath_cache_size_limit; long realpath_cache_ttl; realpath_cache_bucket *realpath_cache[1024]; -#endif } virtual_cwd_globals; #ifdef ZTS @@ -262,7 +242,10 @@ extern virtual_cwd_globals cwd_globals; #endif #define VCWD_CHMOD(path, mode) virtual_chmod(path, mode TSRMLS_CC) #if !defined(TSRM_WIN32) && !defined(NETWARE) -#define VCWD_CHOWN(path, owner, group) virtual_chown(path, owner, group TSRMLS_CC) +#define VCWD_CHOWN(path, owner, group) virtual_chown(path, owner, group, 0 TSRMLS_CC) +#if HAVE_LCHOWN +#define VCWD_LCHOWN(path, owner, group) virtual_chown(path, owner, group, 1 TSRMLS_CC) +#endif #endif #else @@ -305,6 +288,9 @@ extern virtual_cwd_globals cwd_globals; #define VCWD_CHMOD(path, mode) chmod(path, mode) #if !defined(TSRM_WIN32) && !defined(NETWARE) #define VCWD_CHOWN(path, owner, group) chown(path, owner, group) +#if HAVE_LCHOWN +#define VCWD_LCHOWN(path, owner, group) lchown(path, owner, group) +#endif #endif #endif |