cvs: php4 /ext/standard/ basic_functions.h php_ext_syslog.h php_standard.h php_syslog.h syslog.c

[email protected] ("Sascha Schumann")
Newsgroups php.version4
Message-ID <cvssas959530785@cvsserver>
sas		Sun May 28 09:19:45 2000 EDT

  Added files:
    /php4/ext/standard	php_ext_syslog.h 

  Removed files:
    /php4/ext/standard	php_syslog.h 

  Modified files:
    /php4/ext/standard	basic_functions.h php_standard.h syslog.c 
  Log:
  Make syslog module thread-safe. 
  
  
Index: php4/ext/standard/basic_functions.h
diff -u php4/ext/standard/basic_functions.h:1.51 php4/ext/standard/basic_functions.h:1.52
--- php4/ext/standard/basic_functions.h:1.51	Thu Mar 16 08:02:23 2000
+++ php4/ext/standard/basic_functions.h	Sun May 28 09:19:45 2000
@@ -29,7 +29,7 @@
  */
 
 
-/* $Id: basic_functions.h,v 1.51 2000/03/16 16:02:23 andrei Exp $ */
+/* $Id: basic_functions.h,v 1.52 2000/05/28 16:19:45 sas Exp $ */
 
 #ifndef _BASIC_FUNCTIONS_H
 #define _BASIC_FUNCTIONS_H
@@ -162,6 +162,10 @@
 	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
Index: php4/ext/standard/php_standard.h
diff -u php4/ext/standard/php_standard.h:1.3 php4/ext/standard/php_standard.h:1.4
--- php4/ext/standard/php_standard.h:1.3	Mon Mar  6 12:37:11 2000
+++ php4/ext/standard/php_standard.h	Sun May 28 09:19:45 2000
@@ -28,7 +28,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_standard.h,v 1.3 2000/03/06 20:37:11 ssb Exp $ */
+/* $Id: php_standard.h,v 1.4 2000/05/28 16:19:45 sas Exp $ */
 
 #include "basic_functions.h"
 #include "phpmath.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"
Index: php4/ext/standard/syslog.c
diff -u php4/ext/standard/syslog.c:1.19 php4/ext/standard/syslog.c:1.20
--- php4/ext/standard/syslog.c:1.19	Thu May 18 08:34:36 2000
+++ php4/ext/standard/syslog.c	Sun May 28 09:19:45 2000
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: syslog.c,v 1.19 2000/05/18 15:34:36 zeev Exp $ */
+/* $Id: syslog.c,v 1.20 2000/05/28 16:19:45 sas Exp $ */
 
 #include "php.h"
 #include "php_ini.h"
@@ -31,11 +31,10 @@
 #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_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 @@
 	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(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 @@
    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;
 }

Index: php4/ext/standard/php_ext_syslog.h
+++ php4/ext/standard/php_ext_syslog.h
/*
   +----------------------------------------------------------------------+
   | PHP HTML Embedded Scripting Language Version 3.0                     |
   +----------------------------------------------------------------------+
   | Copyright (c) 1997,1998 PHP Development Team (See Credits file)      |
   +----------------------------------------------------------------------+
   | This program is free software; you can redistribute it and/or modify |
   | it under the terms of one of the following licenses:                 |
   |                                                                      |
   |  A) the GNU General Public License as published by the Free Software |
   |     Foundation; either version 2 of the License, or (at your option) |
   |     any later version.                                               |
   |                                                                      |
   |  B) the PHP License as published by the PHP Development Team and     |
   |     included in the distribution in the file: LICENSE                |
   |                                                                      |
   | This program is distributed in the hope that it will be useful,      |
   | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
   | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
   | GNU General Public License for more details.                         |
   |                                                                      |
   | You should have received a copy of both licenses referred to here.   |
   | If you did not, or have any questions about PHP licensing, please    |
   | contact [email protected].                                                |
   +----------------------------------------------------------------------+
   | Authors: Stig Sæther Bakken <[email protected]>                            |
   +----------------------------------------------------------------------+
 */

#ifndef _PHP_EXT_SYSLOG_H
#define _PHP_EXT_SYSLOG_H

#ifdef HAVE_SYSLOG_H

#include "php_syslog.h"

extern PHP_MINIT_FUNCTION(syslog);
extern PHP_RINIT_FUNCTION(syslog);
extern PHP_RSHUTDOWN_FUNCTION(syslog);

PHP_FUNCTION(openlog);
PHP_FUNCTION(syslog);
PHP_FUNCTION(closelog);
PHP_FUNCTION(define_syslog_variables);

#endif

#endif /* _PHP_EXT_SYSLOG_H */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.