/src/php-src/ext/opcache/zend_accelerator_debug.c
Line | Count | Source |
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 | | |
22 | | #include <stdio.h> |
23 | | #include <stdlib.h> |
24 | | #include <stdarg.h> |
25 | | #include <time.h> |
26 | | #ifdef ZEND_WIN32 |
27 | | # include <process.h> |
28 | | #endif |
29 | | #include "ZendAccelerator.h" |
30 | | |
31 | | static void zend_accel_error_va_args(int type, const char *format, va_list args) |
32 | 135k | { |
33 | 135k | time_t timestamp; |
34 | 135k | char *time_string; |
35 | 135k | FILE * fLog = NULL; |
36 | | |
37 | 135k | if (type <= ZCG(accel_directives).log_verbosity_level) { |
38 | |
|
39 | 0 | timestamp = time(NULL); |
40 | 0 | time_string = asctime(localtime(×tamp)); |
41 | 0 | time_string[24] = 0; |
42 | |
|
43 | 0 | if (!ZCG(accel_directives).error_log || |
44 | 0 | !*ZCG(accel_directives).error_log || |
45 | 0 | strcmp(ZCG(accel_directives).error_log, "stderr") == 0) { |
46 | |
|
47 | 0 | fLog = stderr; |
48 | 0 | } else { |
49 | 0 | fLog = fopen(ZCG(accel_directives).error_log, "a"); |
50 | 0 | if (!fLog) { |
51 | 0 | fLog = stderr; |
52 | 0 | } |
53 | 0 | } |
54 | |
|
55 | | #ifdef ZTS |
56 | | fprintf(fLog, "%s (" ZEND_ULONG_FMT "): ", time_string, (zend_ulong)tsrm_thread_id()); |
57 | | #else |
58 | 0 | fprintf(fLog, "%s (%d): ", time_string, getpid()); |
59 | 0 | #endif |
60 | |
|
61 | 0 | switch (type) { |
62 | 0 | case ACCEL_LOG_FATAL: |
63 | 0 | fprintf(fLog, "Fatal Error "); |
64 | 0 | break; |
65 | 0 | case ACCEL_LOG_ERROR: |
66 | 0 | fprintf(fLog, "Error "); |
67 | 0 | break; |
68 | 0 | case ACCEL_LOG_WARNING: |
69 | 0 | fprintf(fLog, "Warning "); |
70 | 0 | break; |
71 | 0 | case ACCEL_LOG_INFO: |
72 | 0 | fprintf(fLog, "Message "); |
73 | 0 | break; |
74 | 0 | case ACCEL_LOG_DEBUG: |
75 | 0 | fprintf(fLog, "Debug "); |
76 | 0 | break; |
77 | 0 | } |
78 | | |
79 | 0 | vfprintf(fLog, format, args); |
80 | 0 | fprintf(fLog, "\n"); |
81 | |
|
82 | 0 | fflush(fLog); |
83 | 0 | if (fLog != stderr) { |
84 | 0 | fclose(fLog); |
85 | 0 | } |
86 | 0 | } |
87 | | /* perform error handling even without logging the error */ |
88 | 135k | switch (type) { |
89 | 0 | case ACCEL_LOG_ERROR: |
90 | 0 | zend_bailout(); |
91 | 0 | break; |
92 | 0 | case ACCEL_LOG_FATAL: |
93 | 0 | exit(-2); |
94 | 0 | break; |
95 | 135k | } |
96 | | |
97 | 135k | } |
98 | | |
99 | | void zend_accel_error(int type, const char *format, ...) |
100 | 135k | { |
101 | 135k | va_list args; |
102 | 135k | va_start(args, format); |
103 | 135k | zend_accel_error_va_args(type, format, args); |
104 | 135k | va_end(args); |
105 | 135k | } |
106 | | |
107 | | ZEND_NORETURN void zend_accel_error_noreturn(int type, const char *format, ...) |
108 | 0 | { |
109 | 0 | va_list args; |
110 | 0 | va_start(args, format); |
111 | 0 | ZEND_ASSERT(type == ACCEL_LOG_FATAL || type == ACCEL_LOG_ERROR); |
112 | 0 | zend_accel_error_va_args(type, format, args); |
113 | 0 | va_end(args); |
114 | | /* Should never reach this. */ |
115 | 0 | abort(); |
116 | 0 | } |