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.

172 lines
4.9 KiB

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