Skip to content

Commit a1f3a01

Browse files
pprindevilleweltling
authored andcommitted
Turn php_syslog() into wrapper for syslog and split lines
1 parent e7c85fc commit a1f3a01

File tree

5 files changed

+93
-19
lines changed

5 files changed

+93
-19
lines changed

Zend/zend_smart_string.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ static zend_always_inline void smart_string_setl(smart_string *dest, char *src,
136136
dest->c = src;
137137
}
138138

139+
static zend_always_inline void smart_string_reset(smart_string *str) {
140+
str->len = 0;
141+
}
142+
139143
#endif
140144

141145
/*

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ PHP_ADD_SOURCES(main, main.c snprintf.c spprintf.c php_sprintf.c \
14431443
php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
14441444
strlcat.c explicit_bzero.c mergesort.c reentrancy.c php_variables.c php_ticks.c \
14451445
network.c php_open_temporary_file.c \
1446-
output.c getopt.c, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
1446+
output.c getopt.c php_syslog.c, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
14471447

14481448
PHP_ADD_SOURCES_X(main, fastcgi.c, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1, PHP_FASTCGI_OBJS, no)
14491449

main/php_syslog.c

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP Version 7 |
4+
+----------------------------------------------------------------------+
5+
| Copyright (c) 2017 The PHP Group |
6+
+----------------------------------------------------------------------+
7+
| This source file is subject to version 3.01 of the PHP license, |
8+
| that is bundled with this package in the file LICENSE, and is |
9+
| available through the world-wide-web at the following url: |
10+
| http://www.php.net/license/3_01.txt |
11+
| If you did not receive a copy of the PHP license and are unable to |
12+
| obtain it through the world-wide-web, please send a note to |
13+
| license@php.net so we can mail you a copy immediately. |
14+
+----------------------------------------------------------------------+
15+
| Author: Philip Prindeville <philipp@redfish-solutions.com> |
16+
+----------------------------------------------------------------------+
17+
*/
18+
19+
/* $Id$ */
20+
21+
#include <stdio.h>
22+
#include <string.h>
23+
#include <assert.h>
24+
#include <stdlib.h>
25+
#include "php.h"
26+
#include "php_syslog.h"
27+
28+
#include "zend.h"
29+
#include "zend_smart_string.h"
30+
31+
/*
32+
* The SCO OpenServer 5 Development System (not the UDK)
33+
* defines syslog to std_syslog.
34+
*/
35+
36+
#ifdef HAVE_STD_SYSLOG
37+
#define syslog std_syslog
38+
#endif
39+
40+
PHPAPI void php_syslog(int priority, const char *format, ...) /* {{{ */
41+
{
42+
const char *ptr;
43+
unsigned char c;
44+
smart_string fbuf = {0};
45+
smart_string sbuf = {0};
46+
va_list args;
47+
48+
va_start(args, format);
49+
zend_printf_to_smart_string(&fbuf, format, args);
50+
smart_string_0(&fbuf);
51+
va_end(args);
52+
53+
for (ptr = fbuf.c; ; ++ptr) {
54+
c = *ptr;
55+
if (c == '\0') {
56+
syslog(priority, "%.*s", (int)sbuf.len, sbuf.c);
57+
break;
58+
}
59+
60+
if (c != '\n')
61+
smart_string_appendc(&sbuf, c);
62+
else {
63+
syslog(priority, "%.*s", (int)sbuf.len, sbuf.c);
64+
smart_string_reset(&sbuf);
65+
}
66+
}
67+
68+
smart_string_free(&fbuf);
69+
smart_string_free(&sbuf);
70+
}
71+
72+
/* }}} */
73+
74+
/*
75+
* Local variables:
76+
* tab-width: 4
77+
* c-basic-offset: 4
78+
* End:
79+
* vim600: sw=4 ts=4 fdm=marker
80+
* vim<600: sw=4 ts=4
81+
*/

main/php_syslog.h

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#ifndef PHP_SYSLOG_H
2222
#define PHP_SYSLOG_H
2323

24+
#include "php.h"
25+
2426
#ifdef PHP_WIN32
2527
#include "win32/syslog.h"
2628
#else
@@ -30,26 +32,12 @@
3032
#endif
3133
#endif
3234

33-
/*
34-
* The SCO OpenServer 5 Development System (not the UDK)
35-
* defines syslog to std_syslog.
36-
*/
37-
38-
#ifdef syslog
39-
40-
#ifdef HAVE_STD_SYSLOG
41-
#define php_syslog std_syslog
42-
#endif
43-
44-
#undef syslog
35+
BEGIN_EXTERN_C()
36+
PHPAPI void php_syslog(int, const char *format, ...);
37+
END_EXTERN_C()
4538

4639
#endif
4740

48-
#ifndef php_syslog
49-
#define php_syslog syslog
50-
#endif
51-
52-
#endif
5341
/*
5442
* Local variables:
5543
* tab-width: 4

win32/build/config.w32

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ ADD_FLAG("CFLAGS_BD_ZEND", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
244244
ADD_SOURCES("main", "main.c snprintf.c spprintf.c getopt.c fopen_wrappers.c \
245245
php_scandir.c php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
246246
strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c network.c \
247-
php_open_temporary_file.c output.c internal_functions.c php_sprintf.c");
247+
php_open_temporary_file.c output.c internal_functions.c php_sprintf.c \
248+
php_syslog.c");
248249
ADD_FLAG("CFLAGS_BD_MAIN", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
249250

250251
AC_DEFINE('HAVE_STRNLEN', 1);

0 commit comments

Comments
 (0)