cvs: php-src /ext/standard basic_functions.c syslog.c /win32 globals.c php_win32_globals.h pwd.c time.c wsyslog.c /win32/build config.w32
| From: | Wez Furlong | Date: | Thu, 29 Jul 2004 02:59:44 +0000 |
| Subject: | cvs: php-src /ext/standard basic_functions.c syslog.c /win32 globals.c php_win32_globals.h pwd.c time.c wsyslog.c /win32/build config.w32 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-28051@lists.php.net to get a copy of this message | ||
wez Wed Jul 28 22:59:44 2004 EDT
Added files:
/php-src/win32 globals.c php_win32_globals.h
Modified files:
/php-src/ext/standard basic_functions.c syslog.c
/php-src/win32 pwd.c time.c wsyslog.c
/php-src/win32/build config.w32
Log:
Misc. win32 thread safety fixes.
http://cvs.php.net/diff.php/php-src/ext/standard/basic_functions.c?r1=1.676&r2=1.677&ty=u Index: php-src/ext/standard/basic_functions.c diff -u php-src/ext/standard/basic_functions.c:1.676 php-src/ext/standard/basic_functions.c:1.677 --- php-src/ext/standard/basic_functions.c:1.676 Thu Jul 22 08:12:28 2004 +++ php-src/ext/standard/basic_functions.c Wed Jul 28 22:59:43 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.676 2004/07/22 12:12:28 wez Exp $ */ +/* $Id: basic_functions.c,v 1.677 2004/07/29 02:59:43 wez Exp $ */ #include "php.h" #include "php_streams.h" @@ -35,6 +35,10 @@ #include "ext/standard/dns.h" #include "ext/standard/php_uuencode.h" +#ifdef PHP_WIN32 +#include "win32/php_win32_globals.h" +#endif + typedef struct yy_buffer_state *YY_BUFFER_STATE; #include "zend.h" @@ -1005,8 +1009,14 @@ { #ifdef ZTS ts_allocate_id(&basic_globals_id, sizeof(php_basic_globals), (ts_allocate_ctor) basic_globals_ctor, (ts_allocate_dtor) basic_globals_dtor); +#ifdef PHP_WIN32 + ts_allocate_id(&php_win32_core_globals_id, sizeof(php_win32_core_globals), (ts_allocate_ctor)php_win32_core_globals_ctor, NULL); +#endif #else basic_globals_ctor(&basic_globals TSRMLS_CC); +#ifdef PHP_WIN32 + php_win32_core_globals_ctor(&php_win32_core_globals TSRMLS_CC); +#endif #endif REGISTER_LONG_CONSTANT("CONNECTION_ABORTED", PHP_CONNECTION_ABORTED, CONST_CS | CONST_PERSISTENT); @@ -1105,6 +1115,9 @@ { #ifdef ZTS ts_free_id(basic_globals_id); +#ifdef PHP_WIN32 + ts_free_id(php_win32_core_globals_id); +#endif #else basic_globals_dtor(&basic_globals TSRMLS_CC); #endif @@ -1214,6 +1227,7 @@ PHP_RSHUTDOWN(assert)(SHUTDOWN_FUNC_ARGS_PASSTHRU); PHP_RSHUTDOWN(url_scanner_ex)(SHUTDOWN_FUNC_ARGS_PASSTHRU); PHP_RSHUTDOWN(streams)(SHUTDOWN_FUNC_ARGS_PASSTHRU); + PHP_RSHUTDOWN(win32_core_globals)(SHUTDOWN_FUNC_ARGS_PASSTHRU); if (BG(user_tick_functions)) { zend_llist_destroy(BG(user_tick_functions)); http://cvs.php.net/diff.php/php-src/ext/standard/syslog.c?r1=1.46&r2=1.47&ty=u Index: php-src/ext/standard/syslog.c diff -u php-src/ext/standard/syslog.c:1.46 php-src/ext/standard/syslog.c:1.47 --- php-src/ext/standard/syslog.c:1.46 Sun Jun 13 13:04:36 2004 +++ php-src/ext/standard/syslog.c Wed Jul 28 22:59:43 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: syslog.c,v 1.46 2004/06/13 17:04:36 iliaa Exp $ */ +/* $Id: syslog.c,v 1.47 2004/07/29 02:59:43 wez Exp $ */ #include "php.h" @@ -119,6 +119,9 @@ if (BG(syslog_device)) { efree(BG(syslog_device)); } +#ifdef PHP_WIN32 + closelog(); +#endif return SUCCESS; } http://cvs.php.net/diff.php/php-src/win32/pwd.c?r1=1.9&r2=1.10&ty=u Index: php-src/win32/pwd.c diff -u php-src/win32/pwd.c:1.9 php-src/win32/pwd.c:1.10 --- php-src/win32/pwd.c:1.9 Thu Jan 8 03:18:21 2004 +++ php-src/win32/pwd.c Wed Jul 28 22:59:43 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pwd.c,v 1.9 2004/01/08 08:18:21 andi Exp $ */ +/* $Id: pwd.c,v 1.10 2004/07/29 02:59:43 wez Exp $ */ #include "php.h" /*php specific */ #include <lmaccess.h> @@ -26,10 +26,7 @@ #include <lmapibuf.h> #include "pwd.h" #include "grp.h" - -#ifndef THREAD_SAFE -static struct passwd pwd; -#endif +#include "php_win32_globals.h" static char *home_dir = "."; static char *login_shell = "not command.com!"; @@ -44,21 +41,26 @@ char * getlogin() { - static char name[256]; + char name[256]; DWORD max_len = 256; + TSRMLS_FETCH(); + STR_FREE(PW32G(login_name)); GetUserName(name, &max_len); - return name; + name[max_len] = '\0'; + PW32G(login_name) = strdup(name); + return PW32G(login_name); } struct passwd * getpwuid(int user_id) { - pwd.pw_name = getlogin(); - pwd.pw_dir = home_dir; - pwd.pw_shell = login_shell; - pwd.pw_uid = 0; + TSRMLS_FETCH(); + PW32G(pwd).pw_name = getlogin(); + PW32G(pwd).pw_dir = home_dir; + PW32G(pwd).pw_shell = login_shell; + PW32G(pwd).pw_uid = 0; - return &pwd; + return &PW32G(pwd); } http://cvs.php.net/diff.php/php-src/win32/time.c?r1=1.9&r2=1.10&ty=u Index: php-src/win32/time.c diff -u php-src/win32/time.c:1.9 php-src/win32/time.c:1.10 --- php-src/win32/time.c:1.9 Mon Jan 12 21:07:04 2004 +++ php-src/win32/time.c Wed Jul 28 22:59:43 2004 @@ -11,7 +11,7 @@ * *****************************************************************************/ -/* $Id: time.c,v 1.9 2004/01/13 02:07:04 wez Exp $ */ +/* $Id: time.c,v 1.10 2004/07/29 02:59:43 wez Exp $ */ /** * @@ -33,6 +33,7 @@ #include <winbase.h> #include <mmsystem.h> #include <errno.h> +#include "php_win32_globals.h" int getfilesystemtime(struct timeval *time_Info) { @@ -51,64 +52,61 @@ PHPAPI int gettimeofday(struct timeval *time_Info, struct timezone *timezone_Info) { - - static struct timeval starttime = {0, 0}; - static __int64 lasttime = 0; - static __int64 freq = 0; __int64 timer; LARGE_INTEGER li; BOOL b; double dt; + TSRMLS_FETCH(); /* Get the time, if they want it */ if (time_Info != NULL) { - if (starttime.tv_sec == 0) { + if (PW32G(starttime).tv_sec == 0) { b = QueryPerformanceFrequency(&li); if (!b) { - starttime.tv_sec = -1; + PW32G(starttime).tv_sec = -1; } else { - freq = li.QuadPart; + PW32G(freq) = li.QuadPart; b = QueryPerformanceCounter(&li); if (!b) { - starttime.tv_sec = -1; + PW32G(starttime).tv_sec = -1; } else { - getfilesystemtime(&starttime); + getfilesystemtime(&PW32G(starttime)); timer = li.QuadPart; - dt = (double)timer/freq; - starttime.tv_usec -= (int)((dt-(int)dt)*1000000); - if (starttime.tv_usec < 0) { - starttime.tv_usec += 1000000; - --starttime.tv_sec; + dt = (double)timer/PW32G(freq); + PW32G(starttime).tv_usec -= (int)((dt-(int)dt)*1000000); + if (PW32G(starttime).tv_usec < 0) { + PW32G(starttime).tv_usec += 1000000; + --PW32G(starttime).tv_sec; } - starttime.tv_sec -= (int)dt; + PW32G(starttime).tv_sec -= (int)dt; } } } - if (starttime.tv_sec > 0) { + if (PW32G(starttime).tv_sec > 0) { b = QueryPerformanceCounter(&li); if (!b) { - starttime.tv_sec = -1; + PW32G(starttime).tv_sec = -1; } else { timer = li.QuadPart; - if (timer < lasttime) { + if (timer < PW32G(lasttime)) { getfilesystemtime(time_Info); - dt = (double)timer/freq; - starttime = *time_Info; - starttime.tv_usec -= (int)((dt-(int)dt)*1000000); - if (starttime.tv_usec < 0) { - starttime.tv_usec += 1000000; - --starttime.tv_sec; + dt = (double)timer/PW32G(freq); + PW32G(starttime) = *time_Info; + PW32G(starttime).tv_usec -= (int)((dt-(int)dt)*1000000); + if (PW32G(starttime).tv_usec < 0) { + PW32G(starttime).tv_usec += 1000000; + --PW32G(starttime).tv_sec; } - starttime.tv_sec -= (int)dt; + PW32G(starttime).tv_sec -= (int)dt; } else { - lasttime = timer; - dt = (double)timer/freq; - time_Info->tv_sec = starttime.tv_sec + (int)dt; - time_Info->tv_usec = starttime.tv_usec + (int)((dt-(int)dt)*1000000); + PW32G(lasttime) = timer; + dt = (double)timer/PW32G(freq); + time_Info->tv_sec = PW32G(starttime).tv_sec + (int)dt; + time_Info->tv_usec = PW32G(starttime).tv_usec + (int)((dt-(int)dt)*1000000); if (time_Info->tv_usec > 1000000) { time_Info->tv_usec -= 1000000; ++time_Info->tv_sec; @@ -116,7 +114,7 @@ } } } - if (starttime.tv_sec < 0) { + if (PW32G(starttime).tv_sec < 0) { getfilesystemtime(time_Info); } @@ -144,6 +142,7 @@ CloseHandle(timer); } +#if 0 /* looks pretty ropey in here */ #ifdef HAVE_SETITIMER @@ -225,3 +224,5 @@ } #endif +#endif + http://cvs.php.net/diff.php/php-src/win32/wsyslog.c?r1=1.4&r2=1.5&ty=u Index: php-src/win32/wsyslog.c diff -u php-src/win32/wsyslog.c:1.4 php-src/win32/wsyslog.c:1.5 --- php-src/win32/wsyslog.c:1.4 Sat Feb 19 08:11:02 2000 +++ php-src/win32/wsyslog.c Wed Jul 28 22:59:43 2004 @@ -56,15 +56,14 @@ #include <fcntl.h> #include <process.h> -#ifndef THREAD_SAFE -static char *loghdr; /* log file header string */ -static HANDLE loghdl = NULL; /* handle of event source */ -#endif +#include "php_win32_globals.h" void closelog(void) { - DeregisterEventSource(loghdl); - efree(loghdr); + TSRMLS_FETCH(); + DeregisterEventSource(PW32G(log_source)); + STR_FREE(PW32G(log_header)); + PW32G(log_header) = NULL; } /* Emulator for BSD syslog() routine @@ -77,12 +76,14 @@ { va_list args; LPTSTR strs[2]; - char tmp[1024]; /* callers must be careful not to pop this */ unsigned short etype; - + char *tmp = NULL; + TSRMLS_FETCH(); + /* default event source */ - if (!loghdl) - openlog("c-client", LOG_PID, LOG_MAIL); + if (!PW32G(log_source)) + openlog("php", LOG_PID, LOG_SYSLOG); + switch (priority) { /* translate UNIX type into NT type */ case LOG_ALERT: etype = EVENTLOG_ERROR_TYPE; @@ -94,12 +95,13 @@ etype = EVENTLOG_WARNING_TYPE; } va_start(args, message); /* initialize vararg mechanism */ - vsprintf(tmp, message, args); /* build message */ - strs[0] = loghdr; /* write header */ + vspprintf(&tmp, 0, message, args); /* build message */ + strs[0] = PW32G(log_header); /* write header */ strs[1] = tmp; /* then the message */ /* report the event */ - ReportEvent(loghdl, etype, (unsigned short) priority, 2000, NULL, 2, 0, strs, NULL); + ReportEvent(PW32G(log_source), etype, (unsigned short) priority, 2000, NULL, 2, 0, strs, NULL); va_end(args); + efree(tmp); } @@ -111,12 +113,14 @@ void openlog(const char *ident, int logopt, int facility) { - char tmp[1024]; + TSRMLS_FETCH(); - if (loghdl) { + if (PW32G(log_source)) { closelog(); } - loghdl = RegisterEventSource(NULL, ident); - sprintf(tmp, (logopt & LOG_PID) ? "%s[%d]" : "%s", ident, getpid()); - loghdr = estrdup(tmp); /* save header for later */ + + STR_FREE(PW32G(log_header)); + + PW32G(log_source) = RegisterEventSource(NULL, ident); + spprintf(&PW32G(log_header), 0, (logopt & LOG_PID) ? "%s[%d]" : "%s", ident, getpid()); } http://cvs.php.net/diff.php/php-src/win32/build/config.w32?r1=1.26&r2=1.27&ty=u Index: php-src/win32/build/config.w32 diff -u php-src/win32/build/config.w32:1.26 php-src/win32/build/config.w32:1.27 --- php-src/win32/build/config.w32:1.26 Thu May 13 08:14:56 2004 +++ php-src/win32/build/config.w32 Wed Jul 28 22:59:44 2004 @@ -1,5 +1,5 @@ // vim:ft=javascript -// $Id: config.w32,v 1.26 2004/05/13 12:14:56 wez Exp $ +// $Id: config.w32,v 1.27 2004/07/29 02:59:44 wez Exp $ // "Master" config file; think of it as a configure.in // equivalent. @@ -194,7 +194,7 @@ userspace.c transports.c xp_socket.c mmap.c"); ADD_SOURCES("win32", "crypt_win32.c flock.c glob.c md5crypt.c pwd.c readdir.c \ - registry.c select.c sendmail.c time.c wfile.c winutil.c wsyslog.c"); + registry.c select.c sendmail.c time.c wfile.c winutil.c wsyslog.c globals.c"); ADD_SOURCES("regex", "regcomp.c regerror.c regexec.c regfree.c"); http://cvs.php.net/co.php/php-src/win32/globals.c?r=1.1&p=1 Index: php-src/win32/globals.c +++ php-src/win32/globals.c /* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2004 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_0.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. | +----------------------------------------------------------------------+ | Author: Wez Furlong <wez@php.net> | +----------------------------------------------------------------------+ */ /* $Id: globals.c,v 1.1 2004/07/29 02:59:43 wez Exp $ */ #include "php.h" #include "php_win32_globals.h" #ifdef ZTS PHPAPI int php_win32_core_globals_id; #else php_win32_core_globals php_win32_core_globals; #endif void php_win32_core_globals_ctor(void *vg TSRMLS_DC) { php_win32_core_globals *wg = (php_win32_core_globals*)vg; memset(wg, 0, sizeof(*wg)); } PHP_RSHUTDOWN_FUNCTION(win32_core_globals) { php_win32_core_globals *wg = #ifdef ZTS ts_resource(php_win32_core_globals_id) #else &php_win32_core_globals #endif ; STR_FREE(wg->login_name); memset(wg, 0, sizeof(*wg)); } http://cvs.php.net/co.php/php-src/win32/php_win32_globals.h?r=1.1&p=1 Index: php-src/win32/php_win32_globals.h +++ php-src/win32/php_win32_globals.h /* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2004 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_0.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. | +----------------------------------------------------------------------+ | Author: Wez Furlong <wez@php.net> | +----------------------------------------------------------------------+ */ /* $Id: php_win32_globals.h,v 1.1 2004/07/29 02:59:43 wez Exp $ */ #ifndef PHP_WIN32_GLOBALS_H #define PHP_WIN32_GLOBALS_H /* misc globals for thread-safety under win32 */ #include "pwd.h" typedef struct _php_win32_core_globals php_win32_core_globals; #ifdef ZTS # define PW32G(v) TSRMG(php_win32_core_globals_id, php_win32_core_globals*, v) extern PHPAPI int php_win32_core_globals_id; #else # define PW32G(v) (php_win32_core_globals.v) extern PHPAPI struct _php_win32_core_globals php_win32_core_globals; #endif struct _php_win32_core_globals { /* syslog */ char *log_header; HANDLE log_source; /* getpwuid */ struct passwd pwd; /* getlogin */ char *login_name; /* time */ struct timeval starttime; __int64 lasttime, freq; }; void php_win32_core_globals_ctor(void *vg TSRMLS_DC); PHP_RSHUTDOWN_FUNCTION(win32_core_globals); #endif
http://cvs.php.net/diff.php/php-src/ext/standard/basic_functions.c?r1=1.676&r2=1.677&ty=u Index: php-src/ext/standard/basic_functions.c diff -u php-src/ext/standard/basic_functions.c:1.676 php-src/ext/standard/basic_functions.c:1.677 --- php-src/ext/standard/basic_functions.c:1.676 Thu Jul 22 08:12:28 2004 +++ php-src/ext/standard/basic_functions.c Wed Jul 28 22:59:43 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.676 2004/07/22 12:12:28 wez Exp $ */ +/* $Id: basic_functions.c,v 1.677 2004/07/29 02:59:43 wez Exp $ */ #include "php.h" #include "php_streams.h" @@ -35,6 +35,10 @@ #include "ext/standard/dns.h" #include "ext/standard/php_uuencode.h" +#ifdef PHP_WIN32 +#include "win32/php_win32_globals.h" +#endif + typedef struct yy_buffer_state *YY_BUFFER_STATE; #include "zend.h" @@ -1005,8 +1009,14 @@ { #ifdef ZTS ts_allocate_id(&basic_globals_id, sizeof(php_basic_globals), (ts_allocate_ctor) basic_globals_ctor, (ts_allocate_dtor) basic_globals_dtor); +#ifdef PHP_WIN32 + ts_allocate_id(&php_win32_core_globals_id, sizeof(php_win32_core_globals), (ts_allocate_ctor)php_win32_core_globals_ctor, NULL); +#endif #else basic_globals_ctor(&basic_globals TSRMLS_CC); +#ifdef PHP_WIN32 + php_win32_core_globals_ctor(&php_win32_core_globals TSRMLS_CC); +#endif #endif REGISTER_LONG_CONSTANT("CONNECTION_ABORTED", PHP_CONNECTION_ABORTED, CONST_CS | CONST_PERSISTENT); @@ -1105,6 +1115,9 @@ { #ifdef ZTS ts_free_id(basic_globals_id); +#ifdef PHP_WIN32 + ts_free_id(php_win32_core_globals_id); +#endif #else basic_globals_dtor(&basic_globals TSRMLS_CC); #endif @@ -1214,6 +1227,7 @@ PHP_RSHUTDOWN(assert)(SHUTDOWN_FUNC_ARGS_PASSTHRU); PHP_RSHUTDOWN(url_scanner_ex)(SHUTDOWN_FUNC_ARGS_PASSTHRU); PHP_RSHUTDOWN(streams)(SHUTDOWN_FUNC_ARGS_PASSTHRU); + PHP_RSHUTDOWN(win32_core_globals)(SHUTDOWN_FUNC_ARGS_PASSTHRU); if (BG(user_tick_functions)) { zend_llist_destroy(BG(user_tick_functions)); http://cvs.php.net/diff.php/php-src/ext/standard/syslog.c?r1=1.46&r2=1.47&ty=u Index: php-src/ext/standard/syslog.c diff -u php-src/ext/standard/syslog.c:1.46 php-src/ext/standard/syslog.c:1.47 --- php-src/ext/standard/syslog.c:1.46 Sun Jun 13 13:04:36 2004 +++ php-src/ext/standard/syslog.c Wed Jul 28 22:59:43 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: syslog.c,v 1.46 2004/06/13 17:04:36 iliaa Exp $ */ +/* $Id: syslog.c,v 1.47 2004/07/29 02:59:43 wez Exp $ */ #include "php.h" @@ -119,6 +119,9 @@ if (BG(syslog_device)) { efree(BG(syslog_device)); } +#ifdef PHP_WIN32 + closelog(); +#endif return SUCCESS; } http://cvs.php.net/diff.php/php-src/win32/pwd.c?r1=1.9&r2=1.10&ty=u Index: php-src/win32/pwd.c diff -u php-src/win32/pwd.c:1.9 php-src/win32/pwd.c:1.10 --- php-src/win32/pwd.c:1.9 Thu Jan 8 03:18:21 2004 +++ php-src/win32/pwd.c Wed Jul 28 22:59:43 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pwd.c,v 1.9 2004/01/08 08:18:21 andi Exp $ */ +/* $Id: pwd.c,v 1.10 2004/07/29 02:59:43 wez Exp $ */ #include "php.h" /*php specific */ #include <lmaccess.h> @@ -26,10 +26,7 @@ #include <lmapibuf.h> #include "pwd.h" #include "grp.h" - -#ifndef THREAD_SAFE -static struct passwd pwd; -#endif +#include "php_win32_globals.h" static char *home_dir = "."; static char *login_shell = "not command.com!"; @@ -44,21 +41,26 @@ char * getlogin() { - static char name[256]; + char name[256]; DWORD max_len = 256; + TSRMLS_FETCH(); + STR_FREE(PW32G(login_name)); GetUserName(name, &max_len); - return name; + name[max_len] = '\0'; + PW32G(login_name) = strdup(name); + return PW32G(login_name); } struct passwd * getpwuid(int user_id) { - pwd.pw_name = getlogin(); - pwd.pw_dir = home_dir; - pwd.pw_shell = login_shell; - pwd.pw_uid = 0; + TSRMLS_FETCH(); + PW32G(pwd).pw_name = getlogin(); + PW32G(pwd).pw_dir = home_dir; + PW32G(pwd).pw_shell = login_shell; + PW32G(pwd).pw_uid = 0; - return &pwd; + return &PW32G(pwd); } http://cvs.php.net/diff.php/php-src/win32/time.c?r1=1.9&r2=1.10&ty=u Index: php-src/win32/time.c diff -u php-src/win32/time.c:1.9 php-src/win32/time.c:1.10 --- php-src/win32/time.c:1.9 Mon Jan 12 21:07:04 2004 +++ php-src/win32/time.c Wed Jul 28 22:59:43 2004 @@ -11,7 +11,7 @@ * *****************************************************************************/ -/* $Id: time.c,v 1.9 2004/01/13 02:07:04 wez Exp $ */ +/* $Id: time.c,v 1.10 2004/07/29 02:59:43 wez Exp $ */ /** * @@ -33,6 +33,7 @@ #include <winbase.h> #include <mmsystem.h> #include <errno.h> +#include "php_win32_globals.h" int getfilesystemtime(struct timeval *time_Info) { @@ -51,64 +52,61 @@ PHPAPI int gettimeofday(struct timeval *time_Info, struct timezone *timezone_Info) { - - static struct timeval starttime = {0, 0}; - static __int64 lasttime = 0; - static __int64 freq = 0; __int64 timer; LARGE_INTEGER li; BOOL b; double dt; + TSRMLS_FETCH(); /* Get the time, if they want it */ if (time_Info != NULL) { - if (starttime.tv_sec == 0) { + if (PW32G(starttime).tv_sec == 0) { b = QueryPerformanceFrequency(&li); if (!b) { - starttime.tv_sec = -1; + PW32G(starttime).tv_sec = -1; } else { - freq = li.QuadPart; + PW32G(freq) = li.QuadPart; b = QueryPerformanceCounter(&li); if (!b) { - starttime.tv_sec = -1; + PW32G(starttime).tv_sec = -1; } else { - getfilesystemtime(&starttime); + getfilesystemtime(&PW32G(starttime)); timer = li.QuadPart; - dt = (double)timer/freq; - starttime.tv_usec -= (int)((dt-(int)dt)*1000000); - if (starttime.tv_usec < 0) { - starttime.tv_usec += 1000000; - --starttime.tv_sec; + dt = (double)timer/PW32G(freq); + PW32G(starttime).tv_usec -= (int)((dt-(int)dt)*1000000); + if (PW32G(starttime).tv_usec < 0) { + PW32G(starttime).tv_usec += 1000000; + --PW32G(starttime).tv_sec; } - starttime.tv_sec -= (int)dt; + PW32G(starttime).tv_sec -= (int)dt; } } } - if (starttime.tv_sec > 0) { + if (PW32G(starttime).tv_sec > 0) { b = QueryPerformanceCounter(&li); if (!b) { - starttime.tv_sec = -1; + PW32G(starttime).tv_sec = -1; } else { timer = li.QuadPart; - if (timer < lasttime) { + if (timer < PW32G(lasttime)) { getfilesystemtime(time_Info); - dt = (double)timer/freq; - starttime = *time_Info; - starttime.tv_usec -= (int)((dt-(int)dt)*1000000); - if (starttime.tv_usec < 0) { - starttime.tv_usec += 1000000; - --starttime.tv_sec; + dt = (double)timer/PW32G(freq); + PW32G(starttime) = *time_Info; + PW32G(starttime).tv_usec -= (int)((dt-(int)dt)*1000000); + if (PW32G(starttime).tv_usec < 0) { + PW32G(starttime).tv_usec += 1000000; + --PW32G(starttime).tv_sec; } - starttime.tv_sec -= (int)dt; + PW32G(starttime).tv_sec -= (int)dt; } else { - lasttime = timer; - dt = (double)timer/freq; - time_Info->tv_sec = starttime.tv_sec + (int)dt; - time_Info->tv_usec = starttime.tv_usec + (int)((dt-(int)dt)*1000000); + PW32G(lasttime) = timer; + dt = (double)timer/PW32G(freq); + time_Info->tv_sec = PW32G(starttime).tv_sec + (int)dt; + time_Info->tv_usec = PW32G(starttime).tv_usec + (int)((dt-(int)dt)*1000000); if (time_Info->tv_usec > 1000000) { time_Info->tv_usec -= 1000000; ++time_Info->tv_sec; @@ -116,7 +114,7 @@ } } } - if (starttime.tv_sec < 0) { + if (PW32G(starttime).tv_sec < 0) { getfilesystemtime(time_Info); } @@ -144,6 +142,7 @@ CloseHandle(timer); } +#if 0 /* looks pretty ropey in here */ #ifdef HAVE_SETITIMER @@ -225,3 +224,5 @@ } #endif +#endif + http://cvs.php.net/diff.php/php-src/win32/wsyslog.c?r1=1.4&r2=1.5&ty=u Index: php-src/win32/wsyslog.c diff -u php-src/win32/wsyslog.c:1.4 php-src/win32/wsyslog.c:1.5 --- php-src/win32/wsyslog.c:1.4 Sat Feb 19 08:11:02 2000 +++ php-src/win32/wsyslog.c Wed Jul 28 22:59:43 2004 @@ -56,15 +56,14 @@ #include <fcntl.h> #include <process.h> -#ifndef THREAD_SAFE -static char *loghdr; /* log file header string */ -static HANDLE loghdl = NULL; /* handle of event source */ -#endif +#include "php_win32_globals.h" void closelog(void) { - DeregisterEventSource(loghdl); - efree(loghdr); + TSRMLS_FETCH(); + DeregisterEventSource(PW32G(log_source)); + STR_FREE(PW32G(log_header)); + PW32G(log_header) = NULL; } /* Emulator for BSD syslog() routine @@ -77,12 +76,14 @@ { va_list args; LPTSTR strs[2]; - char tmp[1024]; /* callers must be careful not to pop this */ unsigned short etype; - + char *tmp = NULL; + TSRMLS_FETCH(); + /* default event source */ - if (!loghdl) - openlog("c-client", LOG_PID, LOG_MAIL); + if (!PW32G(log_source)) + openlog("php", LOG_PID, LOG_SYSLOG); + switch (priority) { /* translate UNIX type into NT type */ case LOG_ALERT: etype = EVENTLOG_ERROR_TYPE; @@ -94,12 +95,13 @@ etype = EVENTLOG_WARNING_TYPE; } va_start(args, message); /* initialize vararg mechanism */ - vsprintf(tmp, message, args); /* build message */ - strs[0] = loghdr; /* write header */ + vspprintf(&tmp, 0, message, args); /* build message */ + strs[0] = PW32G(log_header); /* write header */ strs[1] = tmp; /* then the message */ /* report the event */ - ReportEvent(loghdl, etype, (unsigned short) priority, 2000, NULL, 2, 0, strs, NULL); + ReportEvent(PW32G(log_source), etype, (unsigned short) priority, 2000, NULL, 2, 0, strs, NULL); va_end(args); + efree(tmp); } @@ -111,12 +113,14 @@ void openlog(const char *ident, int logopt, int facility) { - char tmp[1024]; + TSRMLS_FETCH(); - if (loghdl) { + if (PW32G(log_source)) { closelog(); } - loghdl = RegisterEventSource(NULL, ident); - sprintf(tmp, (logopt & LOG_PID) ? "%s[%d]" : "%s", ident, getpid()); - loghdr = estrdup(tmp); /* save header for later */ + + STR_FREE(PW32G(log_header)); + + PW32G(log_source) = RegisterEventSource(NULL, ident); + spprintf(&PW32G(log_header), 0, (logopt & LOG_PID) ? "%s[%d]" : "%s", ident, getpid()); } http://cvs.php.net/diff.php/php-src/win32/build/config.w32?r1=1.26&r2=1.27&ty=u Index: php-src/win32/build/config.w32 diff -u php-src/win32/build/config.w32:1.26 php-src/win32/build/config.w32:1.27 --- php-src/win32/build/config.w32:1.26 Thu May 13 08:14:56 2004 +++ php-src/win32/build/config.w32 Wed Jul 28 22:59:44 2004 @@ -1,5 +1,5 @@ // vim:ft=javascript -// $Id: config.w32,v 1.26 2004/05/13 12:14:56 wez Exp $ +// $Id: config.w32,v 1.27 2004/07/29 02:59:44 wez Exp $ // "Master" config file; think of it as a configure.in // equivalent. @@ -194,7 +194,7 @@ userspace.c transports.c xp_socket.c mmap.c"); ADD_SOURCES("win32", "crypt_win32.c flock.c glob.c md5crypt.c pwd.c readdir.c \ - registry.c select.c sendmail.c time.c wfile.c winutil.c wsyslog.c"); + registry.c select.c sendmail.c time.c wfile.c winutil.c wsyslog.c globals.c"); ADD_SOURCES("regex", "regcomp.c regerror.c regexec.c regfree.c"); http://cvs.php.net/co.php/php-src/win32/globals.c?r=1.1&p=1 Index: php-src/win32/globals.c +++ php-src/win32/globals.c /* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2004 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_0.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. | +----------------------------------------------------------------------+ | Author: Wez Furlong <wez@php.net> | +----------------------------------------------------------------------+ */ /* $Id: globals.c,v 1.1 2004/07/29 02:59:43 wez Exp $ */ #include "php.h" #include "php_win32_globals.h" #ifdef ZTS PHPAPI int php_win32_core_globals_id; #else php_win32_core_globals php_win32_core_globals; #endif void php_win32_core_globals_ctor(void *vg TSRMLS_DC) { php_win32_core_globals *wg = (php_win32_core_globals*)vg; memset(wg, 0, sizeof(*wg)); } PHP_RSHUTDOWN_FUNCTION(win32_core_globals) { php_win32_core_globals *wg = #ifdef ZTS ts_resource(php_win32_core_globals_id) #else &php_win32_core_globals #endif ; STR_FREE(wg->login_name); memset(wg, 0, sizeof(*wg)); } http://cvs.php.net/co.php/php-src/win32/php_win32_globals.h?r=1.1&p=1 Index: php-src/win32/php_win32_globals.h +++ php-src/win32/php_win32_globals.h /* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2004 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_0.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. | +----------------------------------------------------------------------+ | Author: Wez Furlong <wez@php.net> | +----------------------------------------------------------------------+ */ /* $Id: php_win32_globals.h,v 1.1 2004/07/29 02:59:43 wez Exp $ */ #ifndef PHP_WIN32_GLOBALS_H #define PHP_WIN32_GLOBALS_H /* misc globals for thread-safety under win32 */ #include "pwd.h" typedef struct _php_win32_core_globals php_win32_core_globals; #ifdef ZTS # define PW32G(v) TSRMG(php_win32_core_globals_id, php_win32_core_globals*, v) extern PHPAPI int php_win32_core_globals_id; #else # define PW32G(v) (php_win32_core_globals.v) extern PHPAPI struct _php_win32_core_globals php_win32_core_globals; #endif struct _php_win32_core_globals { /* syslog */ char *log_header; HANDLE log_source; /* getpwuid */ struct passwd pwd; /* getlogin */ char *login_name; /* time */ struct timeval starttime; __int64 lasttime, freq; }; void php_win32_core_globals_ctor(void *vg TSRMLS_DC); PHP_RSHUTDOWN_FUNCTION(win32_core_globals); #endif