php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #54144
Patch patch-ext_standard_syslog.diff revision 2011-03-03 00:19 UTC by info at mschuette dot name

Patch patch-ext_standard_syslog.diff for PHP options/info functions Bug #54144

Patch version 2011-03-03 00:19 UTC

Return to Bug #54144 | Download this patch
Patch Revisions:

Developer: info@mschuette.name

--- ext/standard/syslog.c.orig	2010-03-19 15:01:40.000000000 +0100
+++ ext/standard/syslog.c	2010-03-19 15:02:24.000000000 +0100
@@ -38,10 +38,17 @@
 
 static void start_syslog(TSRMLS_D);
 
+PHP_INI_BEGIN()
+PHP_INI_ENTRY("syslog.program", "", PHP_INI_PERDIR, NULL)
+PHP_INI_ENTRY("syslog.pid",    "0", PHP_INI_PERDIR, NULL)
+PHP_INI_END()
+
 /* {{{ PHP_MINIT_FUNCTION
  */
 PHP_MINIT_FUNCTION(syslog)
 {
+	REGISTER_INI_ENTRIES();
+
 	/* 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 */
@@ -105,30 +112,48 @@
 
 PHP_RINIT_FUNCTION(syslog)
 {
+	int option = 0;
+	int facility = LOG_USER;
+
 	if (INI_INT("define_syslog_variables")) {
 		start_syslog(TSRMLS_C);
 	} else {
 		BG(syslog_started)=0;
 	}
-	BG(syslog_device) = NULL;
+
+	if (strlen(INI_STR("syslog.program"))) {
+		BG(syslog_device) = strdup(INI_STR("syslog.program"));
+	} else {
+		BG(syslog_device) = NULL;
+	}
+
+	/* we call openlog() immediately
+	 * a) necessary to have the same options for PHP-internal error reporting,
+	 * b) because there's very little overhead in doing so -- without
+	 *    the LOG_NDELAY option this does not require any syscall
+	 */
+	if (INI_BOOL("syslog.pid")) {
+  	option |= LOG_PID;
+	}
+	openlog(BG(syslog_device), option, facility);
+
 	return SUCCESS;
 }
 
 
-#ifdef PHP_WIN32
 PHP_RSHUTDOWN_FUNCTION(syslog)
 {
 	closelog();
+	if (BG(syslog_device)) {
+		free(BG(syslog_device));
+		BG(syslog_device) = NULL;
+	}
 	return SUCCESS;
 }
-#endif
 
 PHP_MSHUTDOWN_FUNCTION(syslog)
 {
-	if (BG(syslog_device)) {
-		free(BG(syslog_device));
-		BG(syslog_device) = NULL;
-	}
+	UNREGISTER_INI_ENTRIES();
 	return SUCCESS;
 }
 
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Feb 21 00:01:27 2020 UTC