From 429a6bc48393b004a6c90133fa29d1cb2a4e7f85 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 30 Jul 2004 14:37:17 +0000 Subject: [PATCH] MFH: win32 zts fixes --- ext/standard/basic_functions.c | 9 +++++ win32/pwd.c | 24 +++++++------ win32/time.c | 61 +++++++++++++++++----------------- win32/wsyslog.c | 40 ++++++++++++---------- 4 files changed, 75 insertions(+), 59 deletions(-) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 2939dd6173..489611e526 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -1037,8 +1037,14 @@ PHP_MINIT_FUNCTION(basic) { #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); @@ -1125,6 +1131,9 @@ PHP_MSHUTDOWN_FUNCTION(basic) { #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 diff --git a/win32/pwd.c b/win32/pwd.c index 55305d7f56..09485c0dd5 100644 --- a/win32/pwd.c +++ b/win32/pwd.c @@ -28,10 +28,7 @@ #include #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!"; @@ -46,21 +43,26 @@ getpwnam(char *name) 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); } diff --git a/win32/time.c b/win32/time.c index 9f07fab862..ba18ae5717 100644 --- a/win32/time.c +++ b/win32/time.c @@ -28,6 +28,7 @@ #include #include #include +#include "php_win32_globals.h" int getfilesystemtime(struct timeval *time_Info) { @@ -46,64 +47,61 @@ __int64 ff; 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; @@ -111,7 +109,7 @@ PHPAPI int gettimeofday(struct timeval *time_Info, struct timezone *timezone_Inf } } } - if (starttime.tv_sec < 0) { + if (PW32G(starttime).tv_sec < 0) { getfilesystemtime(time_Info); } @@ -159,6 +157,7 @@ struct timeval tnow, tthen, t0; } +#if 0 /* looks pretty ropey in here */ #ifdef HAVE_SETITIMER @@ -240,3 +239,5 @@ PHPAPI int setitimer(int which, const struct itimerval *value, struct itimerval } #endif +#endif + diff --git a/win32/wsyslog.c b/win32/wsyslog.c index 7db5156011..ca1e45b9ca 100644 --- a/win32/wsyslog.c +++ b/win32/wsyslog.c @@ -56,15 +56,14 @@ #include #include -#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 @@ void syslog(int priority, const char *message, ...) { 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 @@ void syslog(int priority, const char *message, ...) 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 syslog(int priority, const char *message, ...) 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()); } -- 2.40.0