Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 691 lines (633 sloc) 20.416 kb
3de3cbf @yaoweibin fix a bug of uninitlization of config with syslog
authored
1 diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
89b04f5 @yaoweibin fix the problem of "-Werror=unused-but-set-variable"
authored
2 index 7986707..9902ef7 100644
3de3cbf @yaoweibin fix a bug of uninitlization of config with syslog
authored
3 --- a/src/core/ngx_cycle.c
4 +++ b/src/core/ngx_cycle.c
28b0fee @yaoweibin add syslog_set
authored
5 @@ -84,6 +84,12 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
3de3cbf @yaoweibin fix a bug of uninitlization of config with syslog
authored
6 cycle->pool = pool;
7 cycle->log = log;
8 cycle->new_log.log_level = NGX_LOG_ERR;
26b705a @yaoweibin add module config script
authored
9 +#if (NGX_ENABLE_SYSLOG)
3de3cbf @yaoweibin fix a bug of uninitlization of config with syslog
authored
10 + cycle->new_log.facility = SYSLOG_FACILITY;
26b705a @yaoweibin add module config script
authored
11 + cycle->new_log.facility = ERR_SYSLOG_PRIORITY;
3de3cbf @yaoweibin fix a bug of uninitlization of config with syslog
authored
12 + cycle->new_log.syslog_on = 0;
28b0fee @yaoweibin add syslog_set
authored
13 + cycle->new_log.syslog_set = 0;
26b705a @yaoweibin add module config script
authored
14 +#endif
3de3cbf @yaoweibin fix a bug of uninitlization of config with syslog
authored
15 cycle->old_cycle = old_cycle;
16
17 cycle->conf_prefix.len = old_cycle->conf_prefix.len;
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
18 diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
499309b @yaoweibin add support for Solaris
authored
19 index 4433314..b8641eb 100644
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
20 --- a/src/core/ngx_log.c
21 +++ b/src/core/ngx_log.c
26b705a @yaoweibin add module config script
authored
22 @@ -9,6 +9,15 @@
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
23
24
25 static char *ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
26b705a @yaoweibin add module config script
authored
26 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
27 +static char *ngx_set_syslog(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
28 +void log_exit(ngx_cycle_t *cycle);
29 +
30 +typedef struct{
31 + ngx_str_t name;
32 + ngx_int_t macro;
33 +} ngx_string_to_macro_t;
26b705a @yaoweibin add module config script
authored
34 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
35
36
37 static ngx_command_t ngx_errlog_commands[] = {
26b705a @yaoweibin add module config script
authored
38 @@ -20,6 +29,15 @@ static ngx_command_t ngx_errlog_commands[] = {
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
39 0,
40 NULL},
41
26b705a @yaoweibin add module config script
authored
42 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
43 + {ngx_string("syslog"),
44 + NGX_MAIN_CONF|NGX_CONF_TAKE12,
45 + ngx_set_syslog,
46 + 0,
47 + 0,
48 + NULL},
26b705a @yaoweibin add module config script
authored
49 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
50 +
51 ngx_null_command
52 };
53
26b705a @yaoweibin add module config script
authored
54 @@ -42,7 +60,11 @@ ngx_module_t ngx_errlog_module = {
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
55 NULL, /* init thread */
56 NULL, /* exit thread */
57 NULL, /* exit process */
58 - NULL, /* exit master */
26b705a @yaoweibin add module config script
authored
59 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
60 + log_exit, /* exit master */
26b705a @yaoweibin add module config script
authored
61 +#else
62 + NULL,
63 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
64 NGX_MODULE_V1_PADDING
65 };
66
499309b @yaoweibin add support for Solaris
authored
67 @@ -51,6 +73,48 @@ static ngx_log_t ngx_log;
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
68 static ngx_open_file_t ngx_log_file;
69 ngx_uint_t ngx_use_stderr = 1;
70
26b705a @yaoweibin add module config script
authored
71 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
72 +static ngx_string_to_macro_t ngx_syslog_facilities[] = {
73 + {ngx_string("auth"), LOG_AUTH},
499309b @yaoweibin add support for Solaris
authored
74 +#if !(NGX_SOLARIS)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
75 + {ngx_string("authpriv"), LOG_AUTHPRIV},
499309b @yaoweibin add support for Solaris
authored
76 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
77 + {ngx_string("cron"), LOG_CRON},
78 + {ngx_string("daemon"), LOG_DAEMON},
499309b @yaoweibin add support for Solaris
authored
79 +#if !(NGX_SOLARIS)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
80 + {ngx_string("ftp"), LOG_FTP},
499309b @yaoweibin add support for Solaris
authored
81 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
82 + {ngx_string("kern"), LOG_KERN},
83 + {ngx_string("local0"), LOG_LOCAL0},
84 + {ngx_string("local1"), LOG_LOCAL1},
85 + {ngx_string("local2"), LOG_LOCAL2},
86 + {ngx_string("local3"), LOG_LOCAL3},
87 + {ngx_string("local4"), LOG_LOCAL4},
88 + {ngx_string("local5"), LOG_LOCAL5},
89 + {ngx_string("local6"), LOG_LOCAL6},
90 + {ngx_string("local7"), LOG_LOCAL7},
91 + {ngx_string("lpr"), LOG_LPR},
92 + {ngx_string("mail"), LOG_MAIL},
93 + {ngx_string("news"), LOG_NEWS},
94 + {ngx_string("syslog"), LOG_SYSLOG},
95 + {ngx_string("user"), LOG_USER},
96 + {ngx_string("uucp"), LOG_UUCP},
97 + { ngx_null_string, 0}
98 +};
99 +
100 +static ngx_string_to_macro_t ngx_syslog_priorities[] = {
101 + {ngx_string("emerg"), LOG_EMERG},
102 + {ngx_string("alert"), LOG_ALERT},
103 + {ngx_string("crit"), LOG_CRIT},
104 + {ngx_string("error"), LOG_ERR},
105 + {ngx_string("err"), LOG_ERR},
106 + {ngx_string("warn"), LOG_WARNING},
107 + {ngx_string("notice"),LOG_NOTICE},
108 + {ngx_string("info"), LOG_INFO},
109 + {ngx_string("debug"), LOG_DEBUG},
110 + { ngx_null_string, 0}
111 +};
26b705a @yaoweibin add module config script
authored
112 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
113
114 static ngx_str_t err_levels[] = {
115 ngx_null_string,
499309b @yaoweibin add support for Solaris
authored
116 @@ -88,11 +152,16 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
117 va_list args;
118 #endif
26b705a @yaoweibin add module config script
authored
119 u_char *p, *last, *msg;
120 +#if (NGX_ENABLE_SYSLOG)
121 + u_char *errstr_syslog;
122 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
123 u_char errstr[NGX_MAX_ERROR_STR];
124
26b705a @yaoweibin add module config script
authored
125 +#if !(NGX_ENABLE_SYSLOG)
126 if (log->file->fd == NGX_INVALID_FILE) {
127 return;
128 }
129 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
130
131 last = errstr + NGX_MAX_ERROR_STR;
132
499309b @yaoweibin add support for Solaris
authored
133 @@ -101,6 +170,10 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
134
135 p = errstr + ngx_cached_err_log_time.len;
136
26b705a @yaoweibin add module config script
authored
137 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
138 + errstr_syslog = p;
26b705a @yaoweibin add module config script
authored
139 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
140 +
141 p = ngx_slprintf(p, last, " [%V] ", &err_levels[level]);
142
143 /* pid#tid */
499309b @yaoweibin add support for Solaris
authored
144 @@ -139,11 +212,27 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
145
146 ngx_linefeed(p);
147
26b705a @yaoweibin add module config script
authored
148 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
149 + if (log->file != NULL && log->file->name.len != 0) {
150 + (void) ngx_write_fd(log->file->fd, errstr, p - errstr);
151 + }
152 +
26b705a @yaoweibin add module config script
authored
153 + /* Don't send the debug level info to syslog */
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
154 + if (log->syslog_on && level < NGX_LOG_DEBUG) {
155 + /* write to syslog */
1fe5833 @yaoweibin fix a bug of compile warning in amd64 server
authored
156 + syslog(log->priority, "%.*s", (int)(p - errstr_syslog), errstr_syslog);
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
157 + }
26b705a @yaoweibin add module config script
authored
158 +#else
159 (void) ngx_write_fd(log->file->fd, errstr, p - errstr);
160 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
161
162 if (!ngx_use_stderr
163 || level > NGX_LOG_WARN
26b705a @yaoweibin add module config script
authored
164 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
165 + || (log->file != NULL && log->file->fd == ngx_stderr))
26b705a @yaoweibin add module config script
authored
166 +#else
167 || log->file->fd == ngx_stderr)
168 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
169 {
170 return;
171 }
499309b @yaoweibin add support for Solaris
authored
172 @@ -364,6 +453,50 @@ ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
173
26b705a @yaoweibin add module config script
authored
174 return log;
175 }
176 +
177 +
178 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
179 +ngx_int_t
180 +ngx_log_get_priority(ngx_conf_t *cf, ngx_str_t *priority)
181 +{
182 + ngx_int_t p = 0;
183 + ngx_uint_t n, match = 0;
184 +
185 + for (n = 0; ngx_syslog_priorities[n].name.len != 0; n++) {
186 + if (ngx_strncmp(priority->data, ngx_syslog_priorities[n].name.data,
187 + ngx_syslog_priorities[n].name.len) == 0) {
188 + p = ngx_syslog_priorities[n].macro;
189 + match = 1;
190 + }
191 + }
192 +
193 + if (!match) {
194 + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
195 + "invalid syslog priority \"%V\"", priority);
196 + return -1;
197 + }
198 +
199 + return p;
200 +}
201 +
202 +
203 +char *
204 +ngx_log_set_priority(ngx_conf_t *cf, ngx_str_t *priority, ngx_log_t *log)
205 +{
206 + log->priority = ERR_SYSLOG_PRIORITY;
207 +
208 + if (priority->len == 0) {
209 + return NGX_CONF_OK;
210 + }
211 +
212 + log->priority = ngx_log_get_priority(cf, priority);
213 + if (log->priority == (-1)) {
214 + return NGX_CONF_ERROR;
215 + }
216 +
217 + return NGX_CONF_OK;
218 +}
26b705a @yaoweibin add module config script
authored
219 +#endif
220
221
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
222 char *
499309b @yaoweibin add support for Solaris
authored
223 @@ -424,6 +557,13 @@ static char *
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
224 ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
225 {
26b705a @yaoweibin add module config script
authored
226 ngx_str_t *value, name;
227 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
228 + u_char *off = NULL;
26b705a @yaoweibin add module config script
authored
229 + ngx_str_t priority;
230 +
231 + ngx_str_null(&name);
232 + ngx_str_null(&priority);
233 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
234
235 if (cf->cycle->new_log.file) {
236 return "is duplicate";
499309b @yaoweibin add support for Solaris
authored
237 @@ -431,7 +571,44 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
238
239 value = cf->args->elts;
240
26b705a @yaoweibin add module config script
authored
241 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
242 + if (ngx_strncmp(value[1].data, "syslog", sizeof("syslog") - 1) == 0) {
28b0fee @yaoweibin add syslog_set
authored
243 + if (!cf->cycle->new_log.syslog_set) {
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
244 + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
245 + "You must set the syslog directive and enable it first.");
246 + return NGX_CONF_ERROR;
247 + }
248 +
28b0fee @yaoweibin add syslog_set
authored
249 + cf->cycle->new_log.syslog_on = 1;
250 +
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
251 + if (value[1].data[sizeof("syslog") - 1] == ':') {
252 + priority.len = value[1].len - sizeof("syslog");
253 + priority.data = value[1].data + sizeof("syslog");
254 +
255 + off = (u_char *)ngx_strchr(priority.data, (int) '|');
256 + if (off != NULL) {
257 + priority.len = off - priority.data;
258 +
259 + off++;
260 + name.len = value[1].data + value[1].len - off;
261 + name.data = off;
262 + }
263 + }
264 + else {
265 + if (value[1].len > sizeof("syslog")) {
266 + name.len = value[1].len - sizeof("syslog");
267 + name.data = value[1].data + sizeof("syslog");
268 + }
269 + }
270 +
271 + if (ngx_log_set_priority(cf, &priority, &cf->cycle->new_log) == NGX_CONF_ERROR) {
272 + return NGX_CONF_ERROR;
273 + }
274 + }
275 + else if (ngx_strcmp(value[1].data, "stderr") == 0) {
26b705a @yaoweibin add module config script
authored
276 +#else
277 if (ngx_strcmp(value[1].data, "stderr") == 0) {
278 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
279 ngx_str_null(&name);
280
281 } else {
499309b @yaoweibin add support for Solaris
authored
282 @@ -452,3 +629,63 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
283
284 return ngx_log_set_levels(cf, &cf->cycle->new_log);
285 }
286 +
287 +
26b705a @yaoweibin add module config script
authored
288 +#if (NGX_ENABLE_SYSLOG)
289 +
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
290 +#define SYSLOG_IDENT_NAME "nginx"
291 +
292 +static char *
293 +ngx_set_syslog(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
294 +{
295 + char *program;
296 + ngx_str_t *value;
297 + ngx_int_t facility, match = 0;
298 + ngx_uint_t n;
299 +
300 + value = cf->args->elts;
301 +
28b0fee @yaoweibin add syslog_set
authored
302 + if (cf->cycle->new_log.syslog_set) {
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
303 + return "is duplicate";
304 + }
305 +
28b0fee @yaoweibin add syslog_set
authored
306 + cf->cycle->new_log.syslog_set = 1;
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
307 +
308 + for (n = 0; ngx_syslog_facilities[n].name.len != 0; n++) {
309 + if (ngx_strncmp(value[1].data, ngx_syslog_facilities[n].name.data,
310 + ngx_syslog_facilities[n].name.len) == 0) {
311 + facility = ngx_syslog_facilities[n].macro;
312 + match = 1;
313 + break;
314 + }
315 + }
316 +
317 + if (match) {
318 + cf->cycle->new_log.facility = facility;
319 + cf->cycle->new_log.priority = ERR_SYSLOG_PRIORITY;
320 + }
321 + else {
322 + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
323 + "invalid syslog facility \"%V\"", &value[1]);
324 + return NGX_CONF_ERROR;
325 + }
326 +
327 + program = SYSLOG_IDENT_NAME;
328 + if (cf->args->nelts > 2) {
329 + program = (char *) value[2].data;
330 + }
331 +
332 + openlog(program, LOG_ODELAY, facility);
333 +
334 + return NGX_CONF_OK;
335 +}
336 +
337 +
338 +void log_exit(ngx_cycle_t *cycle)
339 +{
28b0fee @yaoweibin add syslog_set
authored
340 + if (cycle->new_log.syslog_set) {
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
341 + closelog();
342 + }
343 +}
26b705a @yaoweibin add module config script
authored
344 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
345 +
346 diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h
28b0fee @yaoweibin add syslog_set
authored
347 index 1054836..14288ee 100644
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
348 --- a/src/core/ngx_log.h
349 +++ b/src/core/ngx_log.h
26b705a @yaoweibin add module config script
authored
350 @@ -11,6 +11,13 @@
3de3cbf @yaoweibin fix a bug of uninitlization of config with syslog
authored
351 #include <ngx_config.h>
352 #include <ngx_core.h>
26b705a @yaoweibin add module config script
authored
353
354 +#if (NGX_ENABLE_SYSLOG)
3de3cbf @yaoweibin fix a bug of uninitlization of config with syslog
authored
355 +#include <syslog.h>
356 +
357 +#define SYSLOG_FACILITY LOG_LOCAL5
358 +#define ERR_SYSLOG_PRIORITY LOG_ERR
26b705a @yaoweibin add module config script
authored
359 +#endif
360 +
3de3cbf @yaoweibin fix a bug of uninitlization of config with syslog
authored
361
362 #define NGX_LOG_STDERR 0
26b705a @yaoweibin add module config script
authored
363 #define NGX_LOG_EMERG 1
28b0fee @yaoweibin add syslog_set
authored
364 @@ -60,6 +67,13 @@ struct ngx_log_s {
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
365 */
366
367 char *action;
368 +
26b705a @yaoweibin add module config script
authored
369 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
370 + ngx_int_t priority;
371 + ngx_int_t facility;
372 + unsigned syslog_on:1; /* unsigned :1 syslog_on */
28b0fee @yaoweibin add syslog_set
authored
373 + unsigned syslog_set:1; /*unsigned :1 syslog_set */
26b705a @yaoweibin add module config script
authored
374 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
375 };
376
377
28b0fee @yaoweibin add syslog_set
authored
378 @@ -197,6 +211,10 @@ void ngx_cdecl ngx_log_debug_core(ngx_log_t *log, ngx_err_t err,
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
379
380 ngx_log_t *ngx_log_init(u_char *prefix);
381 ngx_log_t *ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name);
26b705a @yaoweibin add module config script
authored
382 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
383 +ngx_int_t ngx_log_get_priority(ngx_conf_t *cf, ngx_str_t *priority);
384 +char * ngx_log_set_priority(ngx_conf_t *cf, ngx_str_t *priority, ngx_log_t *log);
26b705a @yaoweibin add module config script
authored
385 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
386 char *ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log);
387 void ngx_cdecl ngx_log_abort(ngx_err_t err, const char *fmt, ...);
388 void ngx_cdecl ngx_log_stderr(ngx_err_t err, const char *fmt, ...);
389 diff --git a/src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c
89b04f5 @yaoweibin fix the problem of "-Werror=unused-but-set-variable"
authored
390 index e6a7fdb..51c4384 100644
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
391 --- a/src/http/modules/ngx_http_log_module.c
392 +++ b/src/http/modules/ngx_http_log_module.c
26b705a @yaoweibin add module config script
authored
393 @@ -8,6 +8,11 @@
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
394 #include <ngx_core.h>
395 #include <ngx_http.h>
396
26b705a @yaoweibin add module config script
authored
397 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
398 +#include <syslog.h>
399 +
400 +#define HTTP_SYSLOG_PRIORITY LOG_NOTICE
26b705a @yaoweibin add module config script
authored
401 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
402
403 typedef struct ngx_http_log_op_s ngx_http_log_op_t;
404
26b705a @yaoweibin add module config script
authored
405 @@ -51,6 +56,11 @@ typedef struct {
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
406 time_t disk_full_time;
407 time_t error_log_time;
408 ngx_http_log_fmt_t *format;
409 +
26b705a @yaoweibin add module config script
authored
410 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
411 + ngx_int_t priority;
412 + unsigned syslog_on:1; /* unsigned :1 syslog_on */
26b705a @yaoweibin add module config script
authored
413 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
414 } ngx_http_log_t;
415
416
89b04f5 @yaoweibin fix the problem of "-Werror=unused-but-set-variable"
authored
417 @@ -318,11 +328,27 @@ ngx_http_log_write(ngx_http_request_t *r, ngx_http_log_t *log, u_char *buf,
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
418 time_t now;
26b705a @yaoweibin add module config script
authored
419 ssize_t n;
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
420 ngx_err_t err;
89b04f5 @yaoweibin fix the problem of "-Werror=unused-but-set-variable"
authored
421 -
422 +
26b705a @yaoweibin add module config script
authored
423 +#if (NGX_ENABLE_SYSLOG)
424 + n = 0;
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
425 + if (log->syslog_on) {
1fe5833 @yaoweibin fix a bug of compile warning in amd64 server
authored
426 + syslog(log->priority, "%.*s", (int)len, buf);
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
427 + }
26b705a @yaoweibin add module config script
authored
428 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
429 +
430 if (log->script == NULL) {
26b705a @yaoweibin add module config script
authored
431 name = log->file->name.data;
432 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
433 + if (name != NULL) {
434 + n = ngx_write_fd(log->file->fd, buf, len);
435 + }
0696171 @yaoweibin fix a bug of segment fault
authored
436 + else {
437 + n = len;
438 + }
26b705a @yaoweibin add module config script
authored
439 +#else
440 n = ngx_write_fd(log->file->fd, buf, len);
441
442 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
443 } else {
444 name = NULL;
445 n = ngx_http_log_script_write(r, log->script, &name, buf, len);
89b04f5 @yaoweibin fix the problem of "-Werror=unused-but-set-variable"
authored
446 @@ -836,6 +862,10 @@ ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
26b705a @yaoweibin add module config script
authored
447 log->script = NULL;
3de3cbf @yaoweibin fix a bug of uninitlization of config with syslog
authored
448 log->disk_full_time = 0;
449 log->error_log_time = 0;
26b705a @yaoweibin add module config script
authored
450 +#if (NGX_ENABLE_SYSLOG)
3de3cbf @yaoweibin fix a bug of uninitlization of config with syslog
authored
451 + log->priority = HTTP_SYSLOG_PRIORITY;
452 + log->syslog_on = 0;
26b705a @yaoweibin add module config script
authored
453 +#endif
454
3de3cbf @yaoweibin fix a bug of uninitlization of config with syslog
authored
455 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module);
456 fmt = lmcf->formats.elts;
89b04f5 @yaoweibin fix the problem of "-Werror=unused-but-set-variable"
authored
457 @@ -861,6 +891,13 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
458 ngx_http_log_main_conf_t *lmcf;
459 ngx_http_script_compile_t sc;
460
26b705a @yaoweibin add module config script
authored
461 +#if (NGX_ENABLE_SYSLOG)
462 + u_char *off;
463 + ngx_str_t priority;
464 + ngx_uint_t syslog_on = 0;
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
465 + name = priority = (ngx_str_t)ngx_null_string;
26b705a @yaoweibin add module config script
authored
466 +#endif
467 +
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
468 value = cf->args->elts;
469
470 if (ngx_strcmp(value[1].data, "off") == 0) {
89b04f5 @yaoweibin fix the problem of "-Werror=unused-but-set-variable"
authored
471 @@ -873,6 +910,38 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
472 "invalid parameter \"%V\"", &value[2]);
473 return NGX_CONF_ERROR;
474 }
26b705a @yaoweibin add module config script
authored
475 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
476 + else if (ngx_strncmp(value[1].data, "syslog", sizeof("syslog") - 1) == 0) {
28b0fee @yaoweibin add syslog_set
authored
477 + if (!cf->cycle->new_log.syslog_set) {
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
478 + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
479 + "You must set the syslog directive and enable it first.");
480 + return NGX_CONF_ERROR;
481 + }
482 +
483 + syslog_on = 1;
484 + if (value[1].data[sizeof("syslog") - 1] == ':') {
485 + priority.len = value[1].len - sizeof("syslog");
486 + priority.data = value[1].data + sizeof("syslog");
487 +
488 + off = (u_char*) ngx_strchr(priority.data, '|');
489 + if (off != NULL) {
490 + priority.len = off - priority.data;
491 +
492 + off++;
493 + name.len = value[1].data + value[1].len - off;
494 + name.data = off;
495 + }
496 + }
497 + else {
498 + if (value[1].len > sizeof("syslog")) {
499 + name.len = value[1].len - sizeof("syslog");
500 + name.data = value[1].data + sizeof("syslog");
501 + }
502 + }
503 + } else {
504 + name = value[1];
505 + }
26b705a @yaoweibin add module config script
authored
506 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
507
508 if (llcf->logs == NULL) {
509 llcf->logs = ngx_array_create(cf->pool, 2, sizeof(ngx_http_log_t));
89b04f5 @yaoweibin fix the problem of "-Werror=unused-but-set-variable"
authored
510 @@ -890,6 +959,52 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
511
512 ngx_memzero(log, sizeof(ngx_http_log_t));
513
26b705a @yaoweibin add module config script
authored
514 +#if (NGX_ENABLE_SYSLOG)
0696171 @yaoweibin fix a bug of segment fault
authored
515 + log->syslog_on = syslog_on;
26b705a @yaoweibin add module config script
authored
516 +
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
517 + if (priority.len == 0) {
518 + log->priority = HTTP_SYSLOG_PRIORITY;
519 + }
520 + else {
521 + log->priority = ngx_log_get_priority(cf, &priority);
522 + }
26b705a @yaoweibin add module config script
authored
523 +
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
524 + if (name.len != 0) {
525 + n = ngx_http_script_variables_count(&name);
26b705a @yaoweibin add module config script
authored
526 +
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
527 + if (n == 0) {
528 + log->file = ngx_conf_open_file(cf->cycle, &name);
529 + if (log->file == NULL) {
530 + return NGX_CONF_ERROR;
531 + }
532 + } else {
26b705a @yaoweibin add module config script
authored
533 + if (ngx_conf_full_name(cf->cycle, &name, 0) != NGX_OK) {
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
534 + return NGX_CONF_ERROR;
535 + }
536 + log->script = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_script_t));
537 + if (log->script == NULL) {
538 + return NGX_CONF_ERROR;
539 + }
540 + ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
541 + sc.cf = cf;
542 + sc.source = &name;
543 + sc.lengths = &log->script->lengths;
544 + sc.values = &log->script->values;
545 + sc.variables = n;
546 + sc.complete_lengths = 1;
547 + sc.complete_values = 1;
548 + if (ngx_http_script_compile(&sc) != NGX_OK) {
549 + return NGX_CONF_ERROR;
550 + }
551 + }
552 + }
553 + else {
554 + log->file = ngx_conf_open_file(cf->cycle, &name);
555 + if (log->file == NULL) {
26b705a @yaoweibin add module config script
authored
556 + return NGX_CONF_ERROR;
557 + }
558 + }
559 +#else
560 n = ngx_http_script_variables_count(&value[1]);
561
562 if (n == 0) {
89b04f5 @yaoweibin fix the problem of "-Werror=unused-but-set-variable"
authored
563 @@ -897,7 +1012,7 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
26b705a @yaoweibin add module config script
authored
564 if (log->file == NULL) {
565 return NGX_CONF_ERROR;
566 }
567 -
568 +
569 } else {
570 if (ngx_conf_full_name(cf->cycle, &value[1], 0) != NGX_OK) {
571 return NGX_CONF_ERROR;
89b04f5 @yaoweibin fix the problem of "-Werror=unused-but-set-variable"
authored
572 @@ -922,6 +1037,7 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
573 return NGX_CONF_ERROR;
574 }
575 }
26b705a @yaoweibin add module config script
authored
576 +#endif
577
578 if (cf->args->nelts >= 3) {
579 name = value[2];
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
580 diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
499309b @yaoweibin add support for Solaris
authored
581 index bbb9311..fc08c65 100644
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
582 --- a/src/http/ngx_http_core_module.c
583 +++ b/src/http/ngx_http_core_module.c
499309b @yaoweibin add support for Solaris
authored
584 @@ -1410,6 +1410,9 @@ ngx_http_update_location_config(ngx_http_request_t *r)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
585
586 if (r == r->main) {
587 r->connection->log->file = clcf->error_log->file;
26b705a @yaoweibin add module config script
authored
588 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
589 + r->connection->log->priority = clcf->error_log->priority;
26b705a @yaoweibin add module config script
authored
590 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
591
592 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
593 r->connection->log->log_level = clcf->error_log->log_level;
499309b @yaoweibin add support for Solaris
authored
594 @@ -4440,17 +4443,72 @@ ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
26b705a @yaoweibin add module config script
authored
595
596 ngx_str_t *value;
597
598 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
599 + u_char *off = NULL;
600 + ngx_int_t syslog_on = 0;
601 + ngx_str_t name, priority;
26b705a @yaoweibin add module config script
authored
602 +
603 + name = priority = (ngx_str_t) ngx_null_string;
604 +#endif
605 +
606 if (clcf->error_log) {
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
607 return "is duplicate";
608 }
609
610 value = cf->args->elts;
611
26b705a @yaoweibin add module config script
authored
612 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
613 + if (ngx_strncmp(value[1].data, "syslog", sizeof("syslog") - 1) == 0) {
bfb8761 @yaoweibin fix a bug of config error with "error_log"
authored
614 + if (!cf->cycle->new_log.syslog_set) {
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
615 + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
616 + "You must set the syslog directive and enable it first.");
617 + return NGX_CONF_ERROR;
618 + }
619 +
620 + syslog_on = 1;
621 +
622 + if (value[1].data[sizeof("syslog") - 1] == ':') {
623 + priority.len = value[1].len - sizeof("syslog");
624 + priority.data = value[1].data + sizeof("syslog");
625 +
626 + off = (u_char*) ngx_strchr(priority.data, '|');
627 + if (off != NULL) {
628 + priority.len = off - priority.data;
629 +
630 + off++;
631 + name.len = value[1].data + value[1].len - off;
632 + name.data = off;
633 + }
634 + }
635 + else {
636 + if (value[1].len > sizeof("syslog")) {
637 + name.len = value[1].len - sizeof("syslog");
638 + name.data = value[1].data + sizeof("syslog");
639 + }
640 + }
641 + } else {
642 + name = value[1];
643 + }
644 +
645 + clcf->error_log = ngx_log_create(cf->cycle, &name);
26b705a @yaoweibin add module config script
authored
646 +#else
647 clcf->error_log = ngx_log_create(cf->cycle, &value[1]);
648 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
649 if (clcf->error_log == NULL) {
650 return NGX_CONF_ERROR;
651 }
652
26b705a @yaoweibin add module config script
authored
653 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
654 + if (syslog_on) {
655 + clcf->error_log->syslog_on = 1;
656 + if (ngx_log_set_priority(cf, &priority, clcf->error_log) == NGX_CONF_ERROR) {
657 + return NGX_CONF_ERROR;
658 + }
659 + }
660 +
26b705a @yaoweibin add module config script
authored
661 + clcf->error_log->log_level = 0;
662 +#endif
663 +
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
664 if (cf->args->nelts == 2) {
665 clcf->error_log->log_level = NGX_LOG_ERR;
666 return NGX_CONF_OK;
667 diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
499309b @yaoweibin add support for Solaris
authored
668 index d11b13e..f787e0a 100644
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
669 --- a/src/http/ngx_http_request.c
670 +++ b/src/http/ngx_http_request.c
89b04f5 @yaoweibin fix the problem of "-Werror=unused-but-set-variable"
authored
671 @@ -432,6 +432,9 @@ ngx_http_init_request(ngx_event_t *rev)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
672
673 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
674 c->log->file = clcf->error_log->file;
26b705a @yaoweibin add module config script
authored
675 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
676 + c->log->priority = clcf->error_log->priority;
26b705a @yaoweibin add module config script
authored
677 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
678 if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
679 c->log->log_level = clcf->error_log->log_level;
680 }
499309b @yaoweibin add support for Solaris
authored
681 @@ -1765,6 +1768,9 @@ found:
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
682
683 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
684 r->connection->log->file = clcf->error_log->file;
26b705a @yaoweibin add module config script
authored
685 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
686 + r->connection->log->priority = clcf->error_log->priority;
26b705a @yaoweibin add module config script
authored
687 +#endif
a65d8b3 @yaoweibin add the 0.8.50 patch
authored
688
689 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
690 r->connection->log->log_level = clcf->error_log->log_level;
Something went wrong with that request. Please try again.