Mercurial > hg > nginx
comparison src/core/ngx_log.c @ 461:a88a3e4e158f release-0.1.5
nginx-0.1.5-RELEASE import
*) Bugfix: on Solaris and Linux there may be too many "recvmsg()
returned not enough data" alerts.
*) Bugfix: there were the "writev() failed (22: Invalid argument)"
errors on Solaris in proxy mode without sendfile. On other platforms
that do not support sendfile at all the process got caught in an
endless loop.
*) Bugfix: segmentation fault on Solaris in proxy mode and using
sendfile.
*) Bugfix: segmentation fault on Solaris.
*) Bugfix: on-line upgrade did not work on Linux.
*) Bugfix: the ngx_http_autoindex_module module did not escape the
spaces, the quotes, and the percent signs in the directory listing.
*) Change: the decrease of the copy operations.
*) Feature: the userid_p3p directive.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 11 Nov 2004 14:07:14 +0000 |
parents | 295d97d70c69 |
children | bbd6b0b4a2b1 |
comparison
equal
deleted
inserted
replaced
460:5f8319142dfc | 461:a88a3e4e158f |
---|---|
6 | 6 |
7 #include <ngx_config.h> | 7 #include <ngx_config.h> |
8 #include <ngx_core.h> | 8 #include <ngx_core.h> |
9 | 9 |
10 | 10 |
11 static void ngx_log_write(ngx_log_t *log, char *errstr, size_t len); | 11 static void ngx_log_write(ngx_log_t *log, u_char *errstr, size_t len); |
12 static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 12 static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
13 | 13 |
14 | 14 |
15 static ngx_command_t ngx_errlog_commands[] = { | 15 static ngx_command_t ngx_errlog_commands[] = { |
16 | 16 |
36 NGX_MODULE, | 36 NGX_MODULE, |
37 &ngx_errlog_module_ctx, /* module context */ | 37 &ngx_errlog_module_ctx, /* module context */ |
38 ngx_errlog_commands, /* module directives */ | 38 ngx_errlog_commands, /* module directives */ |
39 NGX_CORE_MODULE, /* module type */ | 39 NGX_CORE_MODULE, /* module type */ |
40 NULL, /* init module */ | 40 NULL, /* init module */ |
41 NULL /* init child */ | 41 NULL /* init process */ |
42 }; | 42 }; |
43 | 43 |
44 | 44 |
45 static ngx_log_t ngx_log; | 45 static ngx_log_t ngx_log; |
46 static ngx_open_file_t ngx_stderr; | 46 static ngx_open_file_t ngx_stderr; |
63 #else | 63 #else |
64 void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, | 64 void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, |
65 const char *fmt, va_list args) | 65 const char *fmt, va_list args) |
66 #endif | 66 #endif |
67 { | 67 { |
68 char errstr[MAX_ERROR_STR]; | |
69 size_t len, max; | |
70 #if (NGX_HAVE_VARIADIC_MACROS) | 68 #if (NGX_HAVE_VARIADIC_MACROS) |
71 va_list args; | 69 va_list args; |
72 #endif | 70 #endif |
71 u_char errstr[NGX_MAX_ERROR_STR], *p, *last; | |
73 | 72 |
74 if (log->file->fd == NGX_INVALID_FILE) { | 73 if (log->file->fd == NGX_INVALID_FILE) { |
75 return; | 74 return; |
76 } | 75 } |
77 | 76 |
77 last = errstr + NGX_MAX_ERROR_STR; | |
78 | |
78 ngx_memcpy(errstr, ngx_cached_err_log_time.data, | 79 ngx_memcpy(errstr, ngx_cached_err_log_time.data, |
79 ngx_cached_err_log_time.len); | 80 ngx_cached_err_log_time.len); |
80 | 81 |
81 #if (WIN32) | 82 p = errstr + ngx_cached_err_log_time.len; |
82 max = MAX_ERROR_STR - 2; | 83 |
83 #else | 84 p = ngx_sprintf(p, " [%s] ", err_levels[level]); |
84 max = MAX_ERROR_STR - 1; | |
85 #endif | |
86 | |
87 len = ngx_cached_err_log_time.len; | |
88 | |
89 len += ngx_snprintf(errstr + len, max - len, " [%s] ", err_levels[level]); | |
90 | 85 |
91 /* pid#tid */ | 86 /* pid#tid */ |
92 len += ngx_snprintf(errstr + len, max - len, | 87 p = ngx_sprintf(p, "%P#" NGX_TID_T_FMT ": ", ngx_log_pid, ngx_log_tid); |
93 PID_T_FMT "#" TID_T_FMT ": ", ngx_log_pid, ngx_log_tid); | |
94 | 88 |
95 if (log->data && *(int *) log->data != -1) { | 89 if (log->data && *(int *) log->data != -1) { |
96 len += ngx_snprintf(errstr + len, max - len, | 90 p = ngx_sprintf(p, "*%ud ", *(u_int *) log->data); |
97 "*%u ", *(u_int *) log->data); | |
98 } | 91 } |
99 | 92 |
100 #if (NGX_HAVE_VARIADIC_MACROS) | 93 #if (NGX_HAVE_VARIADIC_MACROS) |
101 | 94 |
102 va_start(args, fmt); | 95 va_start(args, fmt); |
103 len += ngx_vsnprintf(errstr + len, max - len, fmt, args); | 96 p = ngx_vsnprintf(p, last - p, fmt, args); |
104 va_end(args); | 97 va_end(args); |
105 | 98 |
106 #else | 99 #else |
107 | 100 |
108 len += ngx_vsnprintf(errstr + len, max - len, fmt, args); | 101 p = ngx_vsnprintf(p, last - p, fmt, args); |
109 | 102 |
110 #endif | 103 #endif |
111 | 104 |
112 if (err) { | 105 if (err) { |
113 | 106 |
114 if (len > max - 50) { | 107 if (p > last - 50) { |
115 | 108 |
116 /* leave a space for an error code */ | 109 /* leave a space for an error code */ |
117 | 110 |
118 len = max - 50; | 111 p = last - 50; |
119 errstr[len++] = '.'; | 112 *p++ = '.'; |
120 errstr[len++] = '.'; | 113 *p++ = '.'; |
121 errstr[len++] = '.'; | 114 *p++ = '.'; |
122 } | 115 } |
123 | 116 |
124 #if (WIN32) | 117 #if (NGX_WIN32) |
118 | |
125 if ((unsigned) err >= 0x80000000) { | 119 if ((unsigned) err >= 0x80000000) { |
126 len += ngx_snprintf(errstr + len, max - len, " (%X: ", err); | 120 p = ngx_snprintf(p, last - p, " (%Xd: ", err); |
121 | |
127 } else { | 122 } else { |
128 len += ngx_snprintf(errstr + len, max - len, " (%d: ", err); | 123 p = ngx_snprintf(p, last - p, " (%d: ", err); |
129 } | 124 } |
130 #else | 125 |
131 len += ngx_snprintf(errstr + len, max - len, " (%d: ", err); | 126 #else |
132 #endif | 127 |
133 | 128 p = ngx_snprintf(p, last - p, " (%d: ", err); |
134 if (len >= max) { | 129 |
135 ngx_log_write(log, errstr, max); | 130 #endif |
136 return; | 131 |
137 } | 132 p = ngx_strerror_r(err, p, last - p); |
138 | 133 |
139 len += ngx_strerror_r(err, errstr + len, max - len); | 134 if (p < last) { |
140 | 135 *p++ = ')'; |
141 if (len >= max) { | |
142 ngx_log_write(log, errstr, max); | |
143 return; | |
144 } | |
145 | |
146 errstr[len++] = ')'; | |
147 | |
148 if (len >= max) { | |
149 ngx_log_write(log, errstr, max); | |
150 return; | |
151 } | |
152 | |
153 } else { | |
154 if (len >= max) { | |
155 ngx_log_write(log, errstr, max); | |
156 return; | |
157 } | 136 } |
158 } | 137 } |
159 | 138 |
160 if (level != NGX_LOG_DEBUG && log->handler) { | 139 if (level != NGX_LOG_DEBUG && log->handler) { |
161 len += log->handler(log->data, errstr + len, max - len); | 140 p = log->handler(log->data, p, last - p); |
162 | 141 } |
163 if (len >= max) { | 142 |
164 len = max; | 143 ngx_log_write(log, errstr, p - errstr); |
165 } | 144 } |
166 } | 145 |
167 | 146 |
168 ngx_log_write(log, errstr, len); | 147 static void ngx_log_write(ngx_log_t *log, u_char *errstr, size_t len) |
169 } | 148 { |
170 | 149 #if (NGX_WIN32) |
171 | |
172 static void ngx_log_write(ngx_log_t *log, char *errstr, size_t len) | |
173 { | |
174 #if (WIN32) | |
175 u_long written; | 150 u_long written; |
151 | |
152 if (len >= NGX_MAX_ERROR_STR - 1) { | |
153 len = NGX_MAX_ERROR_STR - 2; | |
154 } | |
176 | 155 |
177 errstr[len++] = CR; | 156 errstr[len++] = CR; |
178 errstr[len++] = LF; | 157 errstr[len++] = LF; |
179 WriteFile(log->file->fd, errstr, len, &written, NULL); | 158 WriteFile(log->file->fd, errstr, len, &written, NULL); |
180 | 159 |
181 #else | 160 #else |
182 | 161 |
162 if (len == NGX_MAX_ERROR_STR) { | |
163 len--; | |
164 } | |
165 | |
183 errstr[len++] = LF; | 166 errstr[len++] = LF; |
184 write(log->file->fd, errstr, len); | 167 write(log->file->fd, errstr, len); |
185 | 168 |
186 #endif | 169 #endif |
187 } | 170 } |
190 #if !(NGX_HAVE_VARIADIC_MACROS) | 173 #if !(NGX_HAVE_VARIADIC_MACROS) |
191 | 174 |
192 void ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, | 175 void ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, |
193 const char *fmt, ...) | 176 const char *fmt, ...) |
194 { | 177 { |
195 va_list args; | 178 va_list args; |
196 | 179 |
197 if (log->log_level >= level) { | 180 if (log->log_level >= level) { |
198 va_start(args, fmt); | 181 va_start(args, fmt); |
199 ngx_log_error_core(level, log, err, fmt, args); | 182 ngx_log_error_core(level, log, err, fmt, args); |
200 va_end(args); | 183 va_end(args); |
202 } | 185 } |
203 | 186 |
204 | 187 |
205 void ngx_log_debug_core(ngx_log_t *log, ngx_err_t err, const char *fmt, ...) | 188 void ngx_log_debug_core(ngx_log_t *log, ngx_err_t err, const char *fmt, ...) |
206 { | 189 { |
207 va_list args; | 190 va_list args; |
208 | 191 |
209 va_start(args, fmt); | 192 va_start(args, fmt); |
210 ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, args); | 193 ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, args); |
211 va_end(args); | 194 va_end(args); |
212 } | 195 } |
213 | 196 |
214 | 197 #endif |
215 void ngx_assert_core(ngx_log_t *log, const char *fmt, ...) | 198 |
216 { | 199 |
217 va_list args; | 200 ngx_log_t *ngx_log_init() |
218 | 201 { |
219 va_start(args, fmt); | |
220 ngx_log_error_core(NGX_LOG_ALERT, log, 0, fmt, args); | |
221 va_end(args); | |
222 } | |
223 | |
224 #endif | |
225 | |
226 | |
227 ngx_log_t *ngx_log_init_stderr() | |
228 { | |
229 #if (WIN32) | |
230 | |
231 ngx_stderr_fileno = GetStdHandle(STD_ERROR_HANDLE); | |
232 ngx_stderr.fd = ngx_stderr_fileno; | |
233 | |
234 if (ngx_stderr_fileno == NGX_INVALID_FILE) { | |
235 | |
236 /* TODO: where can we log error ? */ | |
237 | |
238 return NULL; | |
239 | |
240 } else if (ngx_stderr_fileno == NULL) { | |
241 | |
242 /* there are no associated standard handles */ | |
243 | |
244 /* TODO: where can we can log possible errors ? */ | |
245 | |
246 ngx_stderr.fd = NGX_INVALID_FILE; | |
247 } | |
248 | |
249 #else | |
250 | |
251 ngx_stderr.fd = STDERR_FILENO; | |
252 | |
253 #endif | |
254 | |
255 ngx_log.file = &ngx_stderr; | 202 ngx_log.file = &ngx_stderr; |
256 ngx_log.log_level = NGX_LOG_NOTICE; | 203 ngx_log.log_level = NGX_LOG_NOTICE; |
257 | 204 |
205 #if (NGX_WIN32) | |
206 | |
207 ngx_stderr.fd = ngx_open_file(NGX_ERROR_LOG_PATH, NGX_FILE_RDWR, | |
208 NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); | |
209 | |
210 if (ngx_stderr.fd == NGX_INVALID_FILE) { | |
211 ngx_message_box("nginx", MB_OK, ngx_errno, | |
212 "Could not open error log file: " | |
213 ngx_open_file_n " \"" NGX_ERROR_LOG_PATH "\" failed"); | |
214 return NULL; | |
215 } | |
216 | |
217 if (ngx_file_append_mode(ngx_stderr.fd) == NGX_ERROR) { | |
218 ngx_message_box("nginx", MB_OK, ngx_errno, | |
219 "Could not open error log file: " | |
220 ngx_file_append_mode_n " \"" NGX_ERROR_LOG_PATH | |
221 "\" failed"); | |
222 return NULL; | |
223 } | |
224 | |
225 #else | |
226 | |
227 ngx_stderr.fd = STDERR_FILENO; | |
228 | |
229 #endif | |
230 | |
258 return &ngx_log; | 231 return &ngx_log; |
259 } | 232 } |
260 | |
261 | |
262 #if 0 | |
263 | |
264 ngx_int_t ngx_log_init_error_log() | |
265 { | |
266 ngx_fd_t fd; | |
267 | |
268 #ifdef NGX_ERROR_LOG_PATH | |
269 | |
270 fd = ngx_open_file(NGX_ERROR_LOG_PATH, NGX_FILE_RDWR, | |
271 NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); | |
272 | |
273 if (fd == NGX_INVALID_FILE) { | |
274 ngx_log_error(NGX_LOG_EMERG, (&ngx_log), ngx_errno, | |
275 ngx_open_file_n " \"" NGX_ERROR_LOG_PATH "\" failed"); | |
276 return NGX_ERROR; | |
277 } | |
278 | |
279 #if (WIN32) | |
280 | |
281 if (ngx_file_append_mode(fd) == NGX_ERROR) { | |
282 ngx_log_error(NGX_LOG_EMERG, (&ngx_log), ngx_errno, | |
283 ngx_file_append_mode_n " \"" NGX_ERROR_LOG_PATH | |
284 "\" failed"); | |
285 return NGX_ERROR; | |
286 } | |
287 | |
288 #else | |
289 | |
290 if (dup2(fd, STDERR_FILENO) == NGX_ERROR) { | |
291 ngx_log_error(NGX_LOG_EMERG, (&ngx_log), ngx_errno, | |
292 "dup2(STDERR) failed"); | |
293 return NGX_ERROR; | |
294 } | |
295 | |
296 #endif | |
297 | |
298 #else /* no NGX_ERROR_LOG_PATH */ | |
299 | |
300 ngx_log.log_level = NGX_LOG_INFO; | |
301 | |
302 #endif | |
303 | |
304 return NGX_OK; | |
305 } | |
306 | |
307 #endif | |
308 | 233 |
309 | 234 |
310 ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args) | 235 ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args) |
311 { | 236 { |
312 ngx_log_t *log; | 237 ngx_log_t *log; |