zeev Sat Jan 13 05:59:23 2001 EDT Modified files: /php4/ext/standard exec.c file.c file.h fsock.c fsock.h Log: - Fix exec() bug - Merge fsock and file globals
Index: php4/ext/standard/exec.c diff -u php4/ext/standard/exec.c:1.45 php4/ext/standard/exec.c:1.46 --- php4/ext/standard/exec.c:1.45 Wed Jan 10 05:08:14 2001 +++ php4/ext/standard/exec.c Sat Jan 13 05:59:22 2001 @@ -15,7 +15,7 @@ | Author: Rasmus Lerdorf | +----------------------------------------------------------------------+ */ -/* $Id: exec.c,v 1.45 2001/01/10 13:08:14 thies Exp $ */ +/* $Id: exec.c,v 1.46 2001/01/13 13:59:22 zeev Exp $ */ #include <stdio.h> #include "php.h" @@ -44,11 +44,12 @@ FILE *fp; char *buf, *tmp=NULL; int buflen = 0; - int t, l, ret, output=1; + int t, l, output=1; int overflow_limit, lcmd, ldir; int rsrc_id; char *b, *c, *d=NULL; PLS_FETCH(); + FLS_FETCH(); buf = (char*) emalloc(EXEC_INPUT_BUF); if (!buf) { @@ -123,7 +124,7 @@ * fd gets pclosed */ - rsrc_id = ZEND_REGISTER_RESOURCE(NULL, fp, php_file_le_fopen()); + rsrc_id = ZEND_REGISTER_RESOURCE(NULL, fp, php_file_le_popen()); if (type != 3) { l=0; @@ -195,16 +196,18 @@ /* the zend_list_delete will pclose our popen'ed process */ zend_list_delete(rsrc_id); - + #if HAVE_SYS_WAIT_H - if (WIFEXITED(ret)) { - ret = WEXITSTATUS(ret); + if (WIFEXITED(FG(pclose_ret))) { + ret = WEXITSTATUS(FG(pclose_ret)); } #endif - if (d) efree(d); + if (d) { + efree(d); + } efree(buf); - return ret; + return FG(pclose_ret); } /* {{{ proto int exec(string command [, array output [, int return_value]]) Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.132 php4/ext/standard/file.c:1.133 --- php4/ext/standard/file.c:1.132 Wed Dec 27 07:43:05 2000 +++ php4/ext/standard/file.c Sat Jan 13 05:59:22 2001 @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.132 2000/12/27 15:43:05 zeev Exp $ */ +/* $Id: file.c,v 1.133 2001/01/13 13:59:22 zeev Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -89,25 +89,15 @@ #include "scanf.h" #include "zend_API.h" - -/* }}} */ -/* {{{ ZTS-stuff / Globals / Prototypes */ - -typedef struct { - int fgetss_state; - int pclose_ret; -} php_file_globals; - #ifdef ZTS -#define FIL(v) (file_globals->v) -#define FIL_FETCH() php_file_globals *file_globals = ts_resource(file_globals_id) int file_globals_id; #else -#define FIL(v) (file_globals.v) -#define FIL_FETCH() php_file_globals file_globals; #endif +/* }}} */ +/* {{{ ZTS-stuff / Globals / Prototypes */ + /* sharing globals is *evil* */ static int le_fopen, le_popen, le_socket; @@ -118,8 +108,9 @@ static void _file_popen_dtor(zend_rsrc_list_entry *rsrc) { FILE *pipe = (FILE *)rsrc->ptr; - FIL_FETCH(); - FIL(pclose_ret) = pclose(pipe); + FLS_FETCH(); + + FG(pclose_ret) = pclose(pipe); } @@ -159,10 +150,20 @@ #ifdef ZTS -static void php_file_init_globals(php_file_globals *file_globals) +static void file_globals_ctor(FLS_D) { - FIL(fgetss_state) = 0; - FIL(pclose_ret) = 0; + zend_hash_init(&FG(ht_fsock_keys), 0, NULL, NULL, 1); + zend_hash_init(&FG(ht_fsock_socks), 0, NULL, (void (*)(void +*))php_msock_destroy, 1); + FG(def_chunk_size) = PHP_FSOCK_CHUNK_SIZE; + FG(phpsockbuf) = NULL; + FG(fgetss_state) = 0; + FG(pclose_ret) = 0; +} +static void file_globals_dtor(FLS_D) +{ + zend_hash_destroy(&FG(ht_fsock_socks)); + zend_hash_destroy(&FG(ht_fsock_keys)); + php_cleanup_sockbuf(1 FLS_CC); } #endif @@ -173,10 +174,9 @@ le_socket = zend_register_list_destructors_ex(_file_socket_dtor, NULL, "socket", module_number); #ifdef ZTS - file_globals_id = ts_allocate_id(sizeof(php_file_globals), (ts_allocate_ctor) php_file_init_globals, NULL); + file_globals_id = ts_allocate_id(sizeof(php_file_globals), (ts_allocate_ctor) +file_globals_ctor, (ts_allocate_dtor) file_globals_dtor); #else - FIL(fgetss_state) = 0; - FIL(pclose_ret) = 0; + file_globals_ctor(FLS_C); #endif REGISTER_LONG_CONSTANT("SEEK_SET", SEEK_SET, CONST_CS | CONST_PERSISTENT); @@ -526,7 +526,7 @@ int *sock; int use_include_path = 0; int issock=0, socketd=0; - FIL_FETCH(); + FLS_FETCH(); switch(ARG_COUNT(ht)) { case 2: @@ -565,7 +565,7 @@ } efree(p); - FIL(fgetss_state)=0; + FG(fgetss_state)=0; if (issock) { sock=emalloc(sizeof(int)); @@ -664,7 +664,7 @@ { pval **arg1; void *what; - FIL_FETCH(); + FLS_FETCH(); if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { WRONG_PARAM_COUNT; @@ -674,7 +674,7 @@ ZEND_VERIFY_RESOURCE(what); zend_list_delete((*arg1)->value.lval); - RETURN_LONG(FIL(pclose_ret)); + RETURN_LONG(FG(pclose_ret)); } /* }}} */ @@ -949,7 +949,7 @@ void *what; char *allowed_tags=NULL; int allowed_tags_len=0; - FIL_FETCH(); + FLS_FETCH(); switch(ARG_COUNT(ht)) { case 2: @@ -995,7 +995,7 @@ } /* strlen() can be used here since we are doing it on the return of an fgets() anyway */ - php_strip_tags(buf, strlen(buf), FIL(fgetss_state), allowed_tags, allowed_tags_len); + php_strip_tags(buf, strlen(buf), FG(fgetss_state), allowed_tags, +allowed_tags_len); RETURN_STRING(buf, 0); } Index: php4/ext/standard/file.h diff -u php4/ext/standard/file.h:1.30 php4/ext/standard/file.h:1.31 --- php4/ext/standard/file.h:1.30 Thu Dec 7 04:09:37 2000 +++ php4/ext/standard/file.h Sat Jan 13 05:59:22 2001 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.h,v 1.30 2000/12/07 12:09:37 sas Exp $ */ +/* $Id: file.h,v 1.31 2001/01/13 13:59:22 zeev Exp $ */ /* Synced with php 3.0 revision 1.30 1999-06-16 [ssb] */ @@ -71,5 +71,33 @@ PHPAPI int php_file_le_popen(void); PHPAPI int php_file_le_socket(void); PHPAPI int php_copy_file(char *src, char *dest); + +typedef struct { + int fgetss_state; + int pclose_ret; + HashTable ht_fsock_keys; + HashTable ht_fsock_socks; + struct php_sockbuf *phpsockbuf; + size_t def_chunk_size; +} php_file_globals; + +#ifdef ZTS +#define FLS_D php_file_globals *file_globals +#define FLS_DC , FLS_D +#define FLS_C file_globals +#define FLS_CC , FLS_C +#define FG(v) (file_globals->v) +#define FLS_FETCH() php_file_globals *file_globals = ts_resource(file_globals_id) +extern int file_globals_id; +#else +#define FLS_D void +#define FLS_DC +#define FLS_C +#define FLS_CC +#define FG(v) (file_globals.v) +#define FLS_FETCH() +extern php_file_globals file_globals; +#endif + #endif /* FILE_H */ Index: php4/ext/standard/fsock.c diff -u php4/ext/standard/fsock.c:1.57 php4/ext/standard/fsock.c:1.58 --- php4/ext/standard/fsock.c:1.57 Wed Dec 20 07:51:16 2000 +++ php4/ext/standard/fsock.c Sat Jan 13 05:59:22 2001 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: fsock.c,v 1.57 2000/12/20 15:51:16 andi Exp $ */ +/* $Id: fsock.c,v 1.58 2001/01/13 13:59:22 zeev Exp $ */ /* Synced with php 3.0 revision 1.121 1999-06-18 [ssb] */ /* Synced with php 3.0 revision 1.133 1999-07-21 [sas] */ @@ -357,7 +357,6 @@ } /* }}} */ -#define CHUNK_SIZE 8192 #define SOCK_DESTROY(sock) \ if(sock->readbuf) pefree(sock->readbuf, sock->persistent); \ if(sock->prev) sock->prev->next = sock->next; \ @@ -366,7 +365,7 @@ FG(phpsockbuf) = sock->next; \ pefree(sock, sock->persistent) -static void php_cleanup_sockbuf(int persistent FLS_DC) +void php_cleanup_sockbuf(int persistent FLS_DC) { php_sockbuf *now, *next; @@ -431,7 +430,7 @@ old = FG(def_chunk_size); - if(size <= CHUNK_SIZE || size > 0) + if(size <= PHP_FSOCK_CHUNK_SIZE || size > 0) FG(def_chunk_size) = size; return old; @@ -516,7 +515,7 @@ static size_t php_sockread_internal(php_sockbuf *sock) { - char buf[CHUNK_SIZE]; + char buf[PHP_FSOCK_CHUNK_SIZE]; int nr_bytes; size_t nr_read = 0; @@ -716,28 +715,9 @@ } /* }}} */ -static void fsock_globals_ctor(FLS_D) -{ - zend_hash_init(&FG(ht_fsock_keys), 0, NULL, NULL, 1); - zend_hash_init(&FG(ht_fsock_socks), 0, NULL, (void (*)(void *))php_msock_destroy, 1); - FG(def_chunk_size) = CHUNK_SIZE; - FG(phpsockbuf) = NULL; -} - -static void fsock_globals_dtor(FLS_D) -{ - zend_hash_destroy(&FG(ht_fsock_socks)); - zend_hash_destroy(&FG(ht_fsock_keys)); - php_cleanup_sockbuf(1 FLS_CC); -} PHP_MINIT_FUNCTION(fsock) { -#ifdef ZTS - fsock_globals_id = ts_allocate_id(sizeof(php_fsock_globals), (ts_allocate_ctor) fsock_globals_ctor, (ts_allocate_dtor) fsock_globals_dtor); -#else - fsock_globals_ctor(FLS_C); -#endif return SUCCESS; } Index: php4/ext/standard/fsock.h diff -u php4/ext/standard/fsock.h:1.29 php4/ext/standard/fsock.h:1.30 --- php4/ext/standard/fsock.h:1.29 Sun Jul 23 18:39:49 2000 +++ php4/ext/standard/fsock.h Sat Jan 13 05:59:22 2001 @@ -17,13 +17,15 @@ +----------------------------------------------------------------------+ */ -/* $Id: fsock.h,v 1.29 2000/07/24 01:39:49 david Exp $ */ +/* $Id: fsock.h,v 1.30 2001/01/13 13:59:22 zeev Exp $ */ /* Synced with php 3.0 revision 1.24 1999-06-18 [ssb] */ #ifndef FSOCK_H #define FSOCK_H +#include "file.h" + #ifdef PHP_WIN32 # ifndef WINNT # define WINNT 1 @@ -45,6 +47,8 @@ #include <sys/time.h> #endif +#define PHP_FSOCK_CHUNK_SIZE 8192 + struct php_sockbuf { int socket; unsigned char *readbuf; @@ -78,6 +82,7 @@ int php_sock_close(int socket); size_t php_sock_set_def_chunk_size(size_t size); void php_msock_destroy(int *data); +void php_cleanup_sockbuf(int persistent FLS_DC); PHPAPI int connect_nonb(int sockfd, struct sockaddr *addr, socklen_t addrlen, struct timeval *timeout); PHPAPI struct php_sockbuf *php_get_socket(int socket); @@ -85,28 +90,5 @@ PHP_MINIT_FUNCTION(fsock); PHP_MSHUTDOWN_FUNCTION(fsock); PHP_RSHUTDOWN_FUNCTION(fsock); - -typedef struct { - HashTable ht_fsock_keys; - HashTable ht_fsock_socks; - struct php_sockbuf *phpsockbuf; - size_t def_chunk_size; -} php_fsock_globals; - -#ifdef ZTS -#define FLS_D php_fsock_globals *fsock_globals -#define FLS_DC , FLS_D -#define FLS_C fsock_globals -#define FLS_CC , FLS_C -#define FG(v) (fsock_globals->v) -#define FLS_FETCH() php_fsock_globals *fsock_globals = ts_resource(fsock_globals_id) -#else -#define FLS_D void -#define FLS_DC -#define FLS_C -#define FLS_CC -#define FG(v) (fsock_globals.v) -#define FLS_FETCH() -#endif #endif /* FSOCK_H */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]