From: Sascha Schumann Date: Sun, 28 May 2000 16:19:45 +0000 (+0000) Subject: Make syslog module thread-safe. X-Git-Tag: PRE_EIGHT_BYTE_ALLOC_PATCH~214 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9cd4929417a944a4600875db7018159900bee7b3;p=php Make syslog module thread-safe. --- diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h index db784df0a3..76b7ee5430 100644 --- a/ext/standard/basic_functions.h +++ b/ext/standard/basic_functions.h @@ -162,6 +162,10 @@ typedef struct { php_uint32 state[MT_N+1]; /* state vector + 1 extra to not violate ANSI C */ php_uint32 *next; /* next random value is computed from here */ int left; /* can *next++ this many times before reloading */ + + /* syslog.c */ + int syslog_started; + char *syslog_device; } php_basic_globals; #ifdef ZTS diff --git a/ext/standard/php_syslog.h b/ext/standard/php_ext_syslog.h similarity index 93% rename from ext/standard/php_syslog.h rename to ext/standard/php_ext_syslog.h index 71ec3fdb7c..bf905fb5fc 100644 --- a/ext/standard/php_syslog.h +++ b/ext/standard/php_ext_syslog.h @@ -27,16 +27,12 @@ +----------------------------------------------------------------------+ */ -#ifndef _PHP_SYSLOG_H -#define _PHP_SYSLOG_H +#ifndef _PHP_EXT_SYSLOG_H +#define _PHP_EXT_SYSLOG_H -#if HAVE_SYSLOG_H +#ifdef HAVE_SYSLOG_H -#ifdef PHP_WIN32 -#include "win32/syslog.h" -#else -#include -#endif +#include "php_syslog.h" extern PHP_MINIT_FUNCTION(syslog); extern PHP_RINIT_FUNCTION(syslog); @@ -49,4 +45,4 @@ PHP_FUNCTION(define_syslog_variables); #endif -#endif /* _PHP_SYSLOG_H */ +#endif /* _PHP_EXT_SYSLOG_H */ diff --git a/ext/standard/php_standard.h b/ext/standard/php_standard.h index 9ac91071f2..f87cccf9d5 100644 --- a/ext/standard/php_standard.h +++ b/ext/standard/php_standard.h @@ -42,7 +42,7 @@ #include "html.h" #include "exec.h" #include "file.h" -#include "php_syslog.h" +#include "php_ext_syslog.h" #include "php_filestat.h" #include "php_browscap.h" #include "pack.h" diff --git a/ext/standard/syslog.c b/ext/standard/syslog.c index 8c6f52ac5c..bcc89be78c 100644 --- a/ext/standard/syslog.c +++ b/ext/standard/syslog.c @@ -31,11 +31,10 @@ #include #include -#include "php_syslog.h" +#include "basic_functions.h" +#include "php_ext_syslog.h" -static int syslog_started; -static char *syslog_device; -static void start_syslog(void); +static void start_syslog(BLS_D); PHP_MINIT_FUNCTION(syslog) { @@ -99,26 +98,30 @@ PHP_MINIT_FUNCTION(syslog) PHP_RINIT_FUNCTION(syslog) { + BLS_FETCH(); + if (INI_INT("define_syslog_variables")) { - start_syslog(); + start_syslog(BLS_C); } else { - syslog_started=0; + BG(syslog_started)=0; } - syslog_device=NULL; + BG(syslog_device)=NULL; return SUCCESS; } PHP_RSHUTDOWN_FUNCTION(syslog) { - if (syslog_device) { - efree(syslog_device); + BLS_FETCH(); + + if (BG(syslog_device)) { + efree(BG(syslog_device)); } return SUCCESS; } -static void start_syslog(void) +static void start_syslog(BLS_D) { ELS_FETCH(); @@ -176,15 +179,17 @@ static void start_syslog(void) SET_VAR_LONG("LOG_PERROR", LOG_PERROR); /*log to stderr*/ #endif - syslog_started=1; + BG(syslog_started)=1; } /* {{{ proto void define_syslog_variables(void) Initializes all syslog-related variables */ PHP_FUNCTION(define_syslog_variables) { - if (!syslog_started) { - start_syslog(); + BLS_FETCH(); + + if (!BG(syslog_started)) { + start_syslog(BLS_C); } } @@ -198,17 +203,19 @@ PHP_FUNCTION(define_syslog_variables) PHP_FUNCTION(openlog) { pval **ident, **option, **facility; + BLS_FETCH(); + if (ARG_COUNT(ht) != 3 || zend_get_parameters_ex(3, &ident, &option, &facility) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string_ex(ident); convert_to_long_ex(option); convert_to_long_ex(facility); - if (syslog_device) { - efree(syslog_device); + if (BG(syslog_device)) { + efree(BG(syslog_device)); } - syslog_device = estrndup((*ident)->value.str.val,(*ident)->value.str.len); - openlog(syslog_device, (*option)->value.lval, (*facility)->value.lval); + BG(syslog_device) = estrndup((*ident)->value.str.val,(*ident)->value.str.len); + openlog(BG(syslog_device), (*option)->value.lval, (*facility)->value.lval); RETURN_TRUE; } /* }}} */ @@ -217,10 +224,12 @@ PHP_FUNCTION(openlog) Close connection to system logger */ PHP_FUNCTION(closelog) { + BLS_FETCH(); + closelog(); - if (syslog_device) { - efree(syslog_device); - syslog_device=NULL; + if (BG(syslog_device)) { + efree(BG(syslog_device)); + BG(syslog_device)=NULL; } RETURN_TRUE; }