zend_accelerator_debug.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend OPcache |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 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. | https://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. | Authors: Andi Gutmans <andi@php.net> |
  16. | Zeev Suraski <zeev@php.net> |
  17. | Stanislav Malyshev <stas@zend.com> |
  18. | Dmitry Stogov <dmitry@php.net> |
  19. +----------------------------------------------------------------------+
  20. */
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <stdarg.h>
  24. #include <time.h>
  25. #ifdef ZEND_WIN32
  26. # include <process.h>
  27. #endif
  28. #include "ZendAccelerator.h"
  29. static void zend_accel_error_va_args(int type, const char *format, va_list args)
  30. {
  31. time_t timestamp;
  32. char *time_string;
  33. FILE * fLog = NULL;
  34. if (type <= ZCG(accel_directives).log_verbosity_level) {
  35. timestamp = time(NULL);
  36. time_string = asctime(localtime(&timestamp));
  37. time_string[24] = 0;
  38. if (!ZCG(accel_directives).error_log ||
  39. !*ZCG(accel_directives).error_log ||
  40. strcmp(ZCG(accel_directives).error_log, "stderr") == 0) {
  41. fLog = stderr;
  42. } else {
  43. fLog = fopen(ZCG(accel_directives).error_log, "a");
  44. if (!fLog) {
  45. fLog = stderr;
  46. }
  47. }
  48. #ifdef ZTS
  49. fprintf(fLog, "%s (" ZEND_ULONG_FMT "): ", time_string, (zend_ulong)tsrm_thread_id());
  50. #else
  51. fprintf(fLog, "%s (%d): ", time_string, getpid());
  52. #endif
  53. switch (type) {
  54. case ACCEL_LOG_FATAL:
  55. fprintf(fLog, "Fatal Error ");
  56. break;
  57. case ACCEL_LOG_ERROR:
  58. fprintf(fLog, "Error ");
  59. break;
  60. case ACCEL_LOG_WARNING:
  61. fprintf(fLog, "Warning ");
  62. break;
  63. case ACCEL_LOG_INFO:
  64. fprintf(fLog, "Message ");
  65. break;
  66. case ACCEL_LOG_DEBUG:
  67. fprintf(fLog, "Debug ");
  68. break;
  69. }
  70. vfprintf(fLog, format, args);
  71. fprintf(fLog, "\n");
  72. fflush(fLog);
  73. if (fLog != stderr) {
  74. fclose(fLog);
  75. }
  76. }
  77. /* perform error handling even without logging the error */
  78. switch (type) {
  79. case ACCEL_LOG_ERROR:
  80. zend_bailout();
  81. break;
  82. case ACCEL_LOG_FATAL:
  83. exit(-2);
  84. break;
  85. }
  86. }
  87. void zend_accel_error(int type, const char *format, ...)
  88. {
  89. va_list args;
  90. va_start(args, format);
  91. zend_accel_error_va_args(type, format, args);
  92. va_end(args);
  93. }
  94. ZEND_NORETURN void zend_accel_error_noreturn(int type, const char *format, ...)
  95. {
  96. va_list args;
  97. va_start(args, format);
  98. ZEND_ASSERT(type == ACCEL_LOG_FATAL || type == ACCEL_LOG_ERROR);
  99. zend_accel_error_va_args(type, format, args);
  100. va_end(args);
  101. /* Should never reach this. */
  102. abort();
  103. }