php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #51118
Patch php-syslog.v4.patch.txt revision 2011-07-05 13:31 UTC by fat@php.net
Patch php-syslog.patch revision 2011-01-30 13:31 UTC by fat@php.net
revision 2011-01-30 13:23 UTC by fat@php.net
revision 2011-01-30 10:58 UTC by fat@php.net
Patch php_syslog_multiple_context.patch revision 2011-01-29 13:02 UTC by fat@php.net
revision 2010-07-23 03:23 UTC by fat@php.net

Patch php-syslog.patch for *General Issues Bug #51118

Patch version 2011-01-30 13:31 UTC

Return to Bug #51118 | Download this patch
This patch is obsolete

Obsoleted by patches:

This patch renders other patches obsolete

Obsolete patches:

Patch Revisions: 2011-01-30 13:31 UTC | 2011-01-30 13:23 UTC | 2011-01-30 10:58 UTC

Developer: fat@php.net



  Index: main/php_globals.h
  ===================================================================
  --- main/php_globals.h	(r�vision 307843)
  +++ main/php_globals.h	(copie de travail)
 @@ -160,6 +160,13 @@
 @@ -160,6 +160,15 @@
   	char *mail_log;
   
   	zend_bool in_error_log;
  +
  +#ifdef HAVE_SYSLOG_H
 +	int error_log_facility;
 +	char *error_log_ident;
 +	long error_log_facility;
 +
  +	char *syslog_ident;
  +	int syslog_facility;
  +	int syslog_option;
  +#endif


  @@ -243,7 +243,18 @@
   }
   /* }}} */
   
 +#ifdef HAVE_SYSLOG_H
 +#ifdef HAVE_SYSLOG_H
   /* {{{ PHP_INI_MH
  +*/
  +static PHP_INI_MH(OnUpdateSyslog)
  +{
Line 38 (now 40), was 41 lines, now 37 lines

  +/* {{{ PHP_INI_MH
    */
   static PHP_INI_MH(OnUpdateTimeout)
   {
 @@ -458,6 +469,9 @@
 @@ -458,6 +469,10 @@
   	STD_PHP_INI_ENTRY("default_charset",		SAPI_DEFAULT_CHARSET,	PHP_INI_ALL,	OnUpdateString,			default_charset,		sapi_globals_struct,sapi_globals)
   	STD_PHP_INI_ENTRY("default_mimetype",		SAPI_DEFAULT_MIMETYPE,	PHP_INI_ALL,	OnUpdateString,			default_mimetype,		sapi_globals_struct,sapi_globals)
   	STD_PHP_INI_ENTRY("error_log",				NULL,		PHP_INI_ALL,		OnUpdateErrorLog,			error_log,				php_core_globals,	core_globals)
  +#ifdef HAVE_SYSLOG_H
 +	PHP_INI_ENTRY("error_log_facility",	"LOG_USER",	PHP_INI_ALL,		OnUpdateSyslog)
 +	PHP_INI_ENTRY("error_log_facility",		"LOG_USER",	PHP_INI_ALL,		OnUpdateSyslog)
 +	STD_PHP_INI_ENTRY("error_log_ident",		"php",		PHP_INI_ALL,		OnUpdateString,				error_log_ident,		php_core_globals,	core_globals)
  +#endif
   	STD_PHP_INI_ENTRY("extension_dir",			PHP_EXTENSION_DIR,		PHP_INI_SYSTEM,		OnUpdateStringUnempty,	extension_dir,			php_core_globals,	core_globals)
   	STD_PHP_INI_ENTRY("include_path",			PHP_INCLUDE_PATH,		PHP_INI_ALL,		OnUpdateStringUnempty,	include_path,			php_core_globals,	core_globals)
   	PHP_INI_ENTRY("max_execution_time",			"30",		PHP_INI_ALL,			OnUpdateTimeout)
 @@ -541,6 +555,13 @@
 @@ -541,7 +556,7 @@
   	if (PG(error_log) != NULL) {
   #ifdef HAVE_SYSLOG_H
   		if (!strcmp(PG(error_log), "syslog")) {
 +			if (php_syslog_get_ident()) {
 +				php_closelog();
 +			}
 +			if (php_syslog_get_facility() != PG(error_log_facility) || php_syslog_get_option() != (LOG_PID | LOG_CONS)) {
 +
 +				php_openlog(NULL, LOG_PID | LOG_CONS, PG(error_log_facility));
 +			}
  			php_syslog(LOG_NOTICE, "%s", log_message);
 -			php_syslog(LOG_NOTICE, "%s", log_message);
 +			php_syslog2(INI_STR("error_log_ident"), LOG_PID | LOG_CONS, PG(error_log_facility), LOG_NOTICE, "%s", log_message);
   			PG(in_error_log) = 0;
   			return;
 @@ -1742,6 +1763,7 @@
  		}
 @@ -1742,6 +1757,7 @@
   	memset(core_globals, 0, sizeof(*core_globals));
   
   	php_startup_ticks(TSRMLS_C);
  +	php_startup_syslog(TSRMLS_C);
   }
   /* }}} */
   #endif
 @@ -1763,6 +1785,7 @@
 @@ -1763,6 +1779,7 @@
   		free(core_globals->disable_classes);
   	}
   
  +	php_shutdown_syslog(TSRMLS_C);


  Index: main/php_syslog.c
  ===================================================================
  --- main/php_syslog.c	(r�vision 0)
  +++ main/php_syslog.c	(r�vision 0)
 @@ -0,0 +1,177 @@
 @@ -0,0 +1,217 @@
  +/*
  +   +----------------------------------------------------------------------+
  +   | PHP Version 5                                                        |
  +   +----------------------------------------------------------------------+


  +#ifdef LOG_LOCAL0
  +	SET_LOG(LOG_LOCAL0)
  +#endif
  +#ifdef LOG_LOCAL1
 +	SET_LOG(LOG_LOCAL1)
 +	SET_LOG(LOG_LOCA1)
  +#endif
  +#ifdef LOG_LOCAL2
  +	SET_LOG(LOG_LOCAL2)
  +#endif


  +#endif
  +	
  +};
  +
 +void php_shutdown_syslog(TSRMLS_D) { /* {{{ */
 +void php_shutdown_syslog(TSRMLS_D) /* {{{ */
 +{
  +	if (PG(syslog_ident)) {
  +		free(PG(syslog_ident));
  +	}
 +}
 +/* }}} */
 +
 +void php_startup_syslog(TSRMLS_D) { /* {{{ */
 +}
 +/* }}} */
 +
 +void php_startup_syslog(TSRMLS_D) /* {{{ */
 +{
  +	PG(syslog_ident) = NULL;
  +	PG(syslog_option) = 0;
  +	PG(syslog_facility) = 0;
  +}
  +/* }}} */
  +
 +int php_syslog_get_facility_from_string(char *facility TSRMLS_DC) {
 +int php_syslog_get_facility_from_string(char *facility TSRMLS_DC) /* {{{ */
 +{
  +	int i;
  +	if (facility) {
  +		for (i=0; i<sizeof(facility_names)/sizeof(struct facility_name); i++) {
  +			if (!strcasecmp(facility, facility_names[i].name)) {
  +				return facility_names[i].value;
 +			}
 +			if (strstr(facility_names[i].name, "LOG_") == facility_names[i].name) {
 +				char *tmp = (char *)(facility_names[i].name + strlen("LOG_"));
 +				if (strlen(tmp) > 0) {
 +					if (!strcasecmp(facility, tmp)) {
 +						return facility_names[i].value;
 +					}
 +				}
  +			}
  +		}
  +	}
  +	return LOG_USER;
 +}
 +
 +PHPAPI void php_openlog(const char *new_ident, int new_option, int new_facility) { /* {{{ */
 +}
 +
 +PHPAPI void php_openlog(char *ident, int option, int facility) /* {{{ */
 +{
  +	TSRMLS_FETCH();
  +
  +	/* save current context */
 +	if (PG(syslog_ident)) {
 +		free(PG(syslog_ident));
 +	if (PG(syslog_ident)) {
 +		free(PG(syslog_ident));
  +	}
 +	PG(syslog_ident) =  new_ident ? strdup(new_ident) : NULL;
 +	PG(syslog_option) = new_option;
 +	PG(syslog_facility) = new_facility;
 +	PG(syslog_ident) =  ident ? strdup(ident) : NULL;
 +	PG(syslog_option) = option;
 +	PG(syslog_facility) = facility;
  +
  +	/* then openlog */
 +	openlog(new_ident, new_option, new_facility);
 +}
 +/* }}} */
 +	openlog(ident, option, facility);
 +}
 +/* }}} */
 +
 +PHPAPI void php_syslog2(char *ident, int option, int facility, int priority, const char *fmt, ...) /* {{{ */
 +{
 +	TSRMLS_FETCH();
 +	va_list args;
 +
 +	if (!ident) {
 +		ident = INI_STR("error_log_ident");
 +		option = LOG_PID | LOG_CONS;
 +		facility = php_syslog_get_facility_from_string(INI_STR("error_log_facility"));
 +	}
 +
 +	if (ident) {
 +		if (!PG(syslog_ident) || strcmp(ident, PG(syslog_ident)) !=0 || option != PG(syslog_option) || facility != PG(syslog_facility)) {
 +			php_openlog(ident, option, facility);
 +		}
 +	}
 +
 +	va_start(args, fmt);
 +	php_vsyslog(priority, fmt, args);
 +	va_end(args);
 +}
 +/* }}} */
 +
  +
 +PHPAPI void php_closelog() { /* {{{ */
 +PHPAPI void php_closelog() /* {{{ */
 +{
  +	TSRMLS_FETCH();
  +	/* clear context */
  +	if (PG(syslog_ident)) {
  +		free(PG(syslog_ident));
  +	}
  +	PG(syslog_ident) =  NULL;
  +	PG(syslog_option) = 0;
  +	PG(syslog_facility) = 0;
 +
 +
  +	/* then closelog */
  +	closelog();
  +}
  +/* }}} */
  +
 +PHPAPI char *php_syslog_get_ident() { /* {{{ */
 +	TSRMLS_FETCH();
 +	return PG(syslog_ident);
 +}
 +/* }}} */
 +
 +PHPAPI int php_syslog_get_option() { /* {{{ */
 +PHPAPI char *php_syslog_get_ident() /* {{{ */
 +{
 +	TSRMLS_FETCH();
 +	return PG(syslog_ident);
 +}
 +/* }}} */
 +
 +PHPAPI int php_syslog_get_option() /* {{{ */
 +{
  +	TSRMLS_FETCH();
  +	return PG(syslog_option);
  +}
  +/* }}} */
  +
 +PHPAPI int php_syslog_get_facility() { /* {{{ */
 +PHPAPI int php_syslog_get_facility() /* {{{ */
 +{
  +	TSRMLS_FETCH();
  +	return PG(syslog_facility);
  +}
  +/* }}} */


  Index: main/php_syslog.h
  ===================================================================
  --- main/php_syslog.h	(r�vision 307843)
  +++ main/php_syslog.h	(copie de travail)
 @@ -30,6 +30,20 @@
 @@ -30,6 +30,21 @@
   #endif
   #endif
   
  +


  +void php_startup_syslog(TSRMLS_D);
  +int php_syslog_get_facility_from_string(char *facility TSRMLS_DC);
  +
  +BEGIN_EXTERN_C()
 +PHPAPI void php_openlog(const char *new_ident, int new_option, int new_facility);
 +PHPAPI void php_openlog(char *ident, int option, int facility);
 +PHPAPI void php_syslog2(char *ident, int option, int facility, int priority, const char *fmt, ...);
  +PHPAPI void php_closelog();
  +PHPAPI char *php_syslog_get_ident();
  +PHPAPI int php_syslog_get_option();
  +PHPAPI int php_syslog_get_facility();


  +
   /* 
    * The SCO OpenServer 5 Development System (not the UDK)
    * defines syslog to std_syslog.
 @@ -45,8 +60,16 @@
  
  #endif
  
 +#ifdef vsyslog
 +#undef vsyslog
 +#endif
 +
  #ifndef php_syslog
  #define php_syslog syslog
  #endif
  
 +#ifndef php_vsyslog
 +#define php_vsyslog vsyslog
  #endif
 +
 +#endif
 Index: ext/standard/basic_functions.h
 ===================================================================
 --- ext/standard/basic_functions.h	(r�vision 307843)
 +++ ext/standard/basic_functions.h	(copie de travail)
 @@ -197,7 +197,9 @@
  	zend_bool mt_rand_is_seeded; /* Whether mt_rand() has been seeded */
      
  	/* syslog.c */
 -	char *syslog_device;
 +	char *syslog_ident;
 +	int syslog_option;
 +	int syslog_facility;
  
  	/* var.c */
  	zend_class_entry *incomplete_class;
  Index: ext/standard/syslog.c
  ===================================================================
  --- ext/standard/syslog.c	(r�vision 307843)
  +++ ext/standard/syslog.c	(copie de travail)


   #include "basic_functions.h"
   #include "php_ext_syslog.h"
   
  +static int le_syslog;
 +
 +
  +static void php_syslog_context_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
  +{
  +	php_syslog_context *context = (php_syslog_context*)rsrc->ptr;
  +


  +
   /* {{{ PHP_MINIT_FUNCTION
    */
   PHP_MINIT_FUNCTION(syslog)
  {
  {
  +	le_syslog = zend_register_list_destructors_ex(php_syslog_context_dtor, NULL, PHP_SYSLOG_RES_NAME, module_number);
  +
   	/* error levels */
   	REGISTER_LONG_CONSTANT("LOG_EMERG", LOG_EMERG, CONST_CS | CONST_PERSISTENT); /* system unusable */
   	REGISTER_LONG_CONSTANT("LOG_ALERT", LOG_ALERT, CONST_CS | CONST_PERSISTENT); /* immediate action required */
 @@ -111,7 +127,7 @@
 @@ -95,7 +111,9 @@
  	/* AIX doesn't have LOG_PERROR */
  	REGISTER_LONG_CONSTANT("LOG_PERROR", LOG_PERROR, CONST_CS | CONST_PERSISTENT); /*log to stderr*/
  #endif
 -	BG(syslog_device)=NULL;
 +	BG(syslog_ident)=NULL;
 +	BG(syslog_option)=0;
 +	BG(syslog_facility)=0;
  
  	return SUCCESS;
  }
 @@ -103,7 +121,9 @@
  
  PHP_RINIT_FUNCTION(syslog)
  {
 -	BG(syslog_device) = NULL;
 +	BG(syslog_ident) = NULL;
 +	BG(syslog_option)=0;
 +	BG(syslog_facility)=0;
  	return SUCCESS;
  }
  
 @@ -111,17 +131,19 @@
   #ifdef PHP_WIN32
   PHP_RSHUTDOWN_FUNCTION(syslog)
   {
  -	closelog();
  +	php_closelog();
   	return SUCCESS;
   }
  #endif
 @@ -137,6 +153,7 @@
  #endif
  
  PHP_MSHUTDOWN_FUNCTION(syslog)
  {
 -	if (BG(syslog_device)) {
 -		free(BG(syslog_device));
 -		BG(syslog_device) = NULL;
 +	if (BG(syslog_ident)) {
 +		free(BG(syslog_ident));
 +		BG(syslog_ident) = NULL;
  	}
 +	BG(syslog_option)=0;
 +	BG(syslog_facility)=0;
  	return SUCCESS;
  }
  
 @@ -137,17 +159,27 @@
   	char *ident;
   	long option, facility;
   	int ident_len;
  +	php_syslog_context *context;
   
   	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll", &ident,
   							  &ident_len, &option, &facility) == FAILURE) {
 @@ -146,8 +163,14 @@
  		free(BG(syslog_device));
  		return;
  	}
 -	if (BG(syslog_device)) {
 -		free(BG(syslog_device));
 +	if (BG(syslog_ident)) {
 +		free(BG(syslog_ident));
   	}
  	BG(syslog_device) = zend_strndup(ident, ident_len);
 -	BG(syslog_device) = zend_strndup(ident, ident_len);
  -	openlog(BG(syslog_device), option, facility);
  -	RETURN_TRUE;
 +	php_openlog(BG(syslog_device), option, facility);
 +	BG(syslog_ident) = zend_strndup(ident, ident_len);
 +	BG(syslog_option) = option;
 +	BG(syslog_facility) = facility;
 +
 +	php_openlog(BG(syslog_ident), option, facility);
  +
  +	context = emalloc(sizeof(php_syslog_context));
  +	context->ident = estrndup(ident, ident_len);
  +	context->options = option;


  +	ZEND_REGISTER_RESOURCE(return_value, context, le_syslog);
   }
   /* }}} */
   
 @@ -155,15 +178,29 @@
 @@ -155,15 +187,31 @@
      Close connection to system logger */
   PHP_FUNCTION(closelog)
   {
  -	if (zend_parse_parameters_none() == FAILURE) {


  -		free(BG(syslog_device));
  -		BG(syslog_device)=NULL;
  +	if (zcontext) {
  +		ZEND_FETCH_RESOURCE(context, php_syslog_context*, &zcontext, -1, PHP_SYSLOG_RES_NAME, le_syslog);
 +		if (context && strcmp(context->ident, BG(syslog_device)) != 0) {
 +		if (context && strcmp(context->ident, BG(syslog_ident)) != 0) {
  +			close = 0;
  +		}
  +		zend_list_delete(Z_LVAL_P(zcontext));
   	}
  +
  +	if (close) {
  +		php_closelog();
 +		if (BG(syslog_device)) {
 +			free(BG(syslog_device));
 +			BG(syslog_device)=NULL;
 +		if (BG(syslog_ident)) {
 +			free(BG(syslog_ident));
 +			BG(syslog_ident)=NULL;
  +		}
 +		BG(syslog_option)=0;
 +		BG(syslog_facility)=0;
  +	}
   	RETURN_TRUE;
   }
   /* }}} */
 @@ -175,12 +212,25 @@
 @@ -175,13 +223,23 @@
   	long priority;
   	char *message;
   	int message_len;
  +	zval *zcontext = NULL;
Line 407 (now 525), was 30 lines, now 29 lines

  +							  &message, &message_len, &zcontext) == FAILURE) {
   		return;
   	}
   
 -	php_syslog(priority, "%s", message);
  +	if (zcontext) {
  +		ZEND_FETCH_RESOURCE(context, php_syslog_context*, &zcontext, -1, PHP_SYSLOG_RES_NAME, le_syslog);
 +		if (context && (BG(syslog_device) == NULL || strcmp(BG(syslog_device), context->ident) != 0)) {
 +			if (BG(syslog_device)) {
 +				free(BG(syslog_device));
 +			}
 +			BG(syslog_device) = zend_strndup(context->ident, strlen(context->ident));
 +			php_openlog(context->ident, context->options, context->facility);
 +		if (context) {
 +			php_syslog2(context->ident, context->options, context->facility, priority, "%s", message);
 +			RETURN_TRUE;
  +		}
  +	}
  +
  	php_syslog(priority, "%s", message);
 +	php_syslog2(BG(syslog_ident), BG(syslog_option), BG(syslog_facility), priority, "%s", message);
   	RETURN_TRUE;
   }
  /* }}} */
  Index: ext/standard/php_ext_syslog.h
  ===================================================================
  --- ext/standard/php_ext_syslog.h	(r�vision 307843)
  +++ ext/standard/php_ext_syslog.h	(copie de travail)
  @@ -25,6 +25,14 @@
   
   #include "php_syslog.h"
  
  
  +typedef struct _php_syslog_data {
  +	char *ident;
  +	int options;
  +	int facility;
Line 444 (now 561), was 27 lines, now 26 lines

  Index: sapi/milter/php_milter.c
  ===================================================================
  --- sapi/milter/php_milter.c	(r�vision 307843)
  +++ sapi/milter/php_milter.c	(copie de travail)
 @@ -1162,25 +1162,25 @@
 @@ -1162,25 +1162,23 @@
   			if (stat(sock,&junk) == 0) unlink(sock);
   		}
   
  -		openlog("php-milter", LOG_PID, LOG_MAIL);
 +		php_openlog("php-milter", LOG_PID, LOG_MAIL);
  		
 -		
   		if ((exit_status = mlfi_init())) {
  -			syslog(1, "mlfi_init failed.");
 -			closelog();
 +			php_syslog(1, "mlfi_init failed.");
 -			closelog();
 +			php_syslog2("php-milter", LOG_PID | LOG_CONS, LOG_MAIL, 1, "mlfi_init failed.");
  +			php_closelog();
   			goto err;
   		}
   
   		smfi_setconn(sock);
   		if (smfi_register(smfilter) == MI_FAILURE) {
  -			syslog(1, "smfi_register failed.");
 +			php_syslog(1, "smfi_register failed.");
 +			php_syslog2("php-milter", LOG_PID | LOG_CONS, LOG_MAIL, 1, "smfi_register failed.");
   			fprintf(stderr, "smfi_register failed\n");
  -			closelog();
  +			php_closelog();
   			goto err;


   
   PHP_ADD_SOURCES(main/streams, streams.c cast.c memory.c filter.c \
          plain_wrapper.c userspace.c transports.c xp_socket.c mmap.c \
  Index: php.ini-development
 ===================================================================
 ===================================================================
  --- php.ini-development	(r�vision 307843)
  +++ php.ini-development	(copie de travail)
 @@ -582,6 +582,10 @@
  ; Log errors to syslog (Event Log on NT, not valid in Windows 95).
  ;error_log = syslog
  
 +; Set the syslog facility when error_log is set to 'syslog'
 +;error_log_facility = LOG_USER
 @@ -582,6 +582,12 @@
  ; Log errors to syslog (Event Log on NT, not valid in Windows 95).
  ;error_log = syslog
  
 +; Set the syslog facility when error_log is set to 'syslog'
 +;error_log_facility = LOG_USER
  +
 +; Set the syslog ident when error_log is set to 'syslog'
 +;error_log_facility = php
  +
   ;;;;;;;;;;;;;;;;;
   ; Data Handling ;
   ;;;;;;;;;;;;;;;;;
  Index: php.ini-production
  ===================================================================
  --- php.ini-production	(r�vision 307843)
  +++ php.ini-production	(copie de travail)
 @@ -582,6 +582,9 @@
 @@ -582,6 +582,12 @@
   ; Log errors to syslog (Event Log on NT, not valid in Windows 95).
   ;error_log = syslog
   
  +; Set the syslog facility when error_log is set to 'syslog'
  +;error_log_facility = LOG_USER
 +
 +; Set the syslog ident when error_log is set to 'syslog'
 +;error_log_facility = php
  +
   ;;;;;;;;;;;;;;;;;
   ; Data Handling ;
   ;;;;;;;;;;;;;;;;;
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 04 18:01:29 2024 UTC