You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
5.0 KiB

  1. commit f11d40ef88f640fe4764d2731d3061472aefe556
  2. Author: Philip Prindeville <philipp@redfish-solutions.com>
  3. Date: Wed Aug 9 20:55:25 2017 -0600
  4. Turn php_syslog() into wrapper for syslog and split lines
  5. diff --git a/Zend/zend_smart_string.h b/Zend/zend_smart_string.h
  6. index 2282202..12d755e 100644
  7. --- a/Zend/zend_smart_string.h
  8. +++ b/Zend/zend_smart_string.h
  9. @@ -136,6 +136,10 @@ static zend_always_inline void smart_string_setl(smart_string *dest, char *src,
  10. dest->c = src;
  11. }
  12. +static zend_always_inline void smart_string_reset(smart_string *str) {
  13. + str->len = 0;
  14. +}
  15. +
  16. #endif
  17. /*
  18. diff --git a/configure.ac b/configure.ac
  19. index cb95d86..a63354f 100644
  20. --- a/configure.ac
  21. +++ b/configure.ac
  22. @@ -1478,7 +1478,7 @@ PHP_ADD_SOURCES(main, main.c snprintf.c spprintf.c php_sprintf.c \
  23. php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
  24. strlcat.c explicit_bzero.c mergesort.c reentrancy.c php_variables.c php_ticks.c \
  25. network.c php_open_temporary_file.c \
  26. - output.c getopt.c, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
  27. + output.c getopt.c php_syslog.c, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
  28. PHP_ADD_SOURCES_X(main, fastcgi.c, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1, PHP_FASTCGI_OBJS, no)
  29. diff --git a/main/php_syslog.c b/main/php_syslog.c
  30. new file mode 100644
  31. index 0000000..c351951
  32. --- /dev/null
  33. +++ b/main/php_syslog.c
  34. @@ -0,0 +1,81 @@
  35. +/*
  36. + +----------------------------------------------------------------------+
  37. + | PHP Version 7 |
  38. + +----------------------------------------------------------------------+
  39. + | Copyright (c) 2017 The PHP Group |
  40. + +----------------------------------------------------------------------+
  41. + | This source file is subject to version 3.01 of the PHP license, |
  42. + | that is bundled with this package in the file LICENSE, and is |
  43. + | available through the world-wide-web at the following url: |
  44. + | http://www.php.net/license/3_01.txt |
  45. + | If you did not receive a copy of the PHP license and are unable to |
  46. + | obtain it through the world-wide-web, please send a note to |
  47. + | license@php.net so we can mail you a copy immediately. |
  48. + +----------------------------------------------------------------------+
  49. + | Author: Philip Prindeville <philipp@redfish-solutions.com> |
  50. + +----------------------------------------------------------------------+
  51. +*/
  52. +
  53. +/* $Id$ */
  54. +
  55. +#include <stdio.h>
  56. +#include <string.h>
  57. +#include <assert.h>
  58. +#include <stdlib.h>
  59. +#include "php.h"
  60. +#include "php_syslog.h"
  61. +
  62. +#include "zend.h"
  63. +#include "zend_smart_string.h"
  64. +
  65. +/*
  66. + * The SCO OpenServer 5 Development System (not the UDK)
  67. + * defines syslog to std_syslog.
  68. + */
  69. +
  70. +#ifdef HAVE_STD_SYSLOG
  71. +#define syslog std_syslog
  72. +#endif
  73. +
  74. +PHPAPI void php_syslog(int priority, const char *format, ...) /* {{{ */
  75. +{
  76. + const char *ptr;
  77. + unsigned char c;
  78. + smart_string fbuf = {0};
  79. + smart_string sbuf = {0};
  80. + va_list args;
  81. +
  82. + va_start(args, format);
  83. + zend_printf_to_smart_string(&fbuf, format, args);
  84. + smart_string_0(&fbuf);
  85. + va_end(args);
  86. +
  87. + for (ptr = fbuf.c; ; ++ptr) {
  88. + c = *ptr;
  89. + if (c == '\0') {
  90. + syslog(priority, "%.*s", (int)sbuf.len, sbuf.c);
  91. + break;
  92. + }
  93. +
  94. + if (c != '\n')
  95. + smart_string_appendc(&sbuf, c);
  96. + else {
  97. + syslog(priority, "%.*s", (int)sbuf.len, sbuf.c);
  98. + smart_string_reset(&sbuf);
  99. + }
  100. + }
  101. +
  102. + smart_string_free(&fbuf);
  103. + smart_string_free(&sbuf);
  104. +}
  105. +
  106. +/* }}} */
  107. +
  108. +/*
  109. + * Local variables:
  110. + * tab-width: 4
  111. + * c-basic-offset: 4
  112. + * End:
  113. + * vim600: sw=4 ts=4 fdm=marker
  114. + * vim<600: sw=4 ts=4
  115. + */
  116. diff --git a/main/php_syslog.h b/main/php_syslog.h
  117. index be68cc4..4c4ca4e 100644
  118. --- a/main/php_syslog.h
  119. +++ b/main/php_syslog.h
  120. @@ -21,6 +21,8 @@
  121. #ifndef PHP_SYSLOG_H
  122. #define PHP_SYSLOG_H
  123. +#include "php.h"
  124. +
  125. #ifdef PHP_WIN32
  126. #include "win32/syslog.h"
  127. #else
  128. @@ -30,26 +32,12 @@
  129. #endif
  130. #endif
  131. -/*
  132. - * The SCO OpenServer 5 Development System (not the UDK)
  133. - * defines syslog to std_syslog.
  134. - */
  135. -
  136. -#ifdef syslog
  137. -
  138. -#ifdef HAVE_STD_SYSLOG
  139. -#define php_syslog std_syslog
  140. -#endif
  141. -
  142. -#undef syslog
  143. +BEGIN_EXTERN_C()
  144. +PHPAPI void php_syslog(int, const char *format, ...);
  145. +END_EXTERN_C()
  146. #endif
  147. -#ifndef php_syslog
  148. -#define php_syslog syslog
  149. -#endif
  150. -
  151. -#endif
  152. /*
  153. * Local variables:
  154. * tab-width: 4
  155. diff --git a/win32/build/config.w32 b/win32/build/config.w32
  156. index 6cbb18b..71cf491 100644
  157. --- a/win32/build/config.w32
  158. +++ b/win32/build/config.w32
  159. @@ -241,7 +241,8 @@ ADD_FLAG("CFLAGS_BD_ZEND", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
  160. ADD_SOURCES("main", "main.c snprintf.c spprintf.c getopt.c fopen_wrappers.c \
  161. php_scandir.c php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
  162. strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c network.c \
  163. - php_open_temporary_file.c output.c internal_functions.c php_sprintf.c");
  164. + php_open_temporary_file.c output.c internal_functions.c php_sprintf.c \
  165. + php_syslog.c");
  166. ADD_FLAG("CFLAGS_BD_MAIN", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
  167. AC_DEFINE('HAVE_STRNLEN', 1);