-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Handle newlines correctly when error_log set to "syslog" #2674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
+----------------------------------------------------------------------+ | ||
| PHP Version 7 | | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) 2017 The PHP Group | | ||
+----------------------------------------------------------------------+ | ||
| This source file is subject to version 3.01 of the PHP license, | | ||
| that is bundled with this package in the file LICENSE, and is | | ||
| available through the world-wide-web at the following url: | | ||
| http://www.php.net/license/3_01.txt | | ||
| If you did not receive a copy of the PHP license and are unable to | | ||
| obtain it through the world-wide-web, please send a note to | | ||
| license@php.net so we can mail you a copy immediately. | | ||
+----------------------------------------------------------------------+ | ||
| Author: Philip Prindeville <philipp@redfish-solutions.com> | | ||
+----------------------------------------------------------------------+ | ||
*/ | ||
|
||
/* $Id$ */ | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
#include <assert.h> | ||
#include <stdlib.h> | ||
#include "php.h" | ||
#include "php_syslog.h" | ||
|
||
#include "zend.h" | ||
#include "zend_smart_string.h" | ||
|
||
/* | ||
* The SCO OpenServer 5 Development System (not the UDK) | ||
* defines syslog to std_syslog. | ||
*/ | ||
|
||
#ifdef HAVE_STD_SYSLOG | ||
#define syslog std_syslog | ||
#endif | ||
|
||
PHPAPI void php_syslog(int priority, const char *format, ...) /* {{{ */ | ||
{ | ||
const char *ptr; | ||
unsigned char c; | ||
smart_string fbuf = {0}; | ||
smart_string sbuf = {0}; | ||
va_list args; | ||
|
||
va_start(args, format); | ||
zend_printf_to_smart_string(&fbuf, format, args); | ||
smart_string_0(&fbuf); | ||
va_end(args); | ||
|
||
for (ptr = fbuf.c; ; ++ptr) { | ||
c = *ptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it could be inside the |
||
if (c == '\0') { | ||
syslog(priority, "%.*s", (int)sbuf.len, sbuf.c); | ||
break; | ||
} | ||
|
||
if (c != '\n') | ||
smart_string_appendc(&sbuf, c); | ||
else { | ||
syslog(priority, "%.*s", (int)sbuf.len, sbuf.c); | ||
smart_string_reset(&sbuf); | ||
} | ||
} | ||
|
||
smart_string_free(&fbuf); | ||
smart_string_free(&sbuf); | ||
} | ||
|
||
/* }}} */ | ||
|
||
/* | ||
* Local variables: | ||
* tab-width: 4 | ||
* c-basic-offset: 4 | ||
* End: | ||
* vim600: sw=4 ts=4 fdm=marker | ||
* vim<600: sw=4 ts=4 | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ | |
#ifndef PHP_SYSLOG_H | ||
#define PHP_SYSLOG_H | ||
|
||
#include "php.h" | ||
|
||
#ifdef PHP_WIN32 | ||
#include "win32/syslog.h" | ||
#else | ||
|
@@ -30,26 +32,12 @@ | |
#endif | ||
#endif | ||
|
||
/* | ||
* The SCO OpenServer 5 Development System (not the UDK) | ||
* defines syslog to std_syslog. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment should be kept somewhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
#ifdef syslog | ||
|
||
#ifdef HAVE_STD_SYSLOG | ||
#define php_syslog std_syslog | ||
#endif | ||
|
||
#undef syslog | ||
BEGIN_EXTERN_C() | ||
PHPAPI void php_syslog(int, const char *format, ...); | ||
END_EXTERN_C() | ||
|
||
#endif | ||
|
||
#ifndef php_syslog | ||
#define php_syslog syslog | ||
#endif | ||
|
||
#endif | ||
/* | ||
* Local variables: | ||
* tab-width: 4 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
php_syslog.c should also be added to the Windows build system in win32/build/config.w32
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.