]> granicus.if.org Git - php/commitdiff
Make syslog module thread-safe.
authorSascha Schumann <sas@php.net>
Sun, 28 May 2000 16:19:45 +0000 (16:19 +0000)
committerSascha Schumann <sas@php.net>
Sun, 28 May 2000 16:19:45 +0000 (16:19 +0000)
ext/standard/basic_functions.h
ext/standard/php_ext_syslog.h [moved from ext/standard/php_syslog.h with 93% similarity]
ext/standard/php_standard.h
ext/standard/syslog.c

index db784df0a32844dcce3b7164c848c0499415d4ea..76b7ee5430caf9da0cc0e926b09f99a1ed0185d2 100644 (file)
@@ -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
similarity index 93%
rename from ext/standard/php_syslog.h
rename to ext/standard/php_ext_syslog.h
index 71ec3fdb7cf92574768701b46e7438f991b02791..bf905fb5fc30edd0cb6a74f15fb2e4e44268c1d5 100644 (file)
    +----------------------------------------------------------------------+
  */
 
-#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 <syslog.h>
-#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 */
index 9ac91071f262240035439b5d11dc7293e2e60568..f87cccf9d53f8edc3e8f36540e54f7987b767723 100644 (file)
@@ -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"
index 8c6f52ac5c088060af6749faea6ee21d66ae4b72..bcc89be78ce2f3cae40d90a32cf994a0e98722c6 100644 (file)
 #include <errno.h>
 
 #include <stdio.h>
-#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;
 }