Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 689 lines (630 sloc) 20.388 kb
3de3cbf Weibin Yao(姚伟斌) 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
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
2 index 357c6b2..53053da 100644
3de3cbf Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add syslog_set
authored
5 @@ -84,6 +84,12 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
3de3cbf Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add module config script
authored
9 +#if (NGX_ENABLE_SYSLOG)
3de3cbf Weibin Yao(姚伟斌) fix a bug of uninitlization of config with syslog
authored
10 + cycle->new_log.facility = SYSLOG_FACILITY;
26b705a Weibin Yao(姚伟斌) add module config script
authored
11 + cycle->new_log.facility = ERR_SYSLOG_PRIORITY;
3de3cbf Weibin Yao(姚伟斌) fix a bug of uninitlization of config with syslog
authored
12 + cycle->new_log.syslog_on = 0;
28b0fee Weibin Yao(姚伟斌) add syslog_set
authored
13 + cycle->new_log.syslog_set = 0;
26b705a Weibin Yao(姚伟斌) add module config script
authored
14 +#endif
3de3cbf Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
18 diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
19 index c0485c6..e744aa2 100644
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
20 --- a/src/core/ngx_log.c
21 +++ b/src/core/ngx_log.c
26b705a Weibin Yao(姚伟斌) add module config script
authored
22 @@ -9,6 +9,15 @@
a65d8b3 Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add module config script
authored
26 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add module config script
authored
34 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
35
36
37 static ngx_command_t ngx_errlog_commands[] = {
26b705a Weibin Yao(姚伟斌) add module config script
authored
38 @@ -20,6 +29,15 @@ static ngx_command_t ngx_errlog_commands[] = {
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
39 0,
40 NULL},
41
26b705a Weibin Yao(姚伟斌) add module config script
authored
42 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add module config script
authored
49 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
50 +
51 ngx_null_command
52 };
53
26b705a Weibin Yao(姚伟斌) add module config script
authored
54 @@ -42,7 +60,11 @@ ngx_module_t ngx_errlog_module = {
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
55 NULL, /* init thread */
56 NULL, /* exit thread */
57 NULL, /* exit process */
58 - NULL, /* exit master */
26b705a Weibin Yao(姚伟斌) add module config script
authored
59 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
60 + log_exit, /* exit master */
26b705a Weibin Yao(姚伟斌) add module config script
authored
61 +#else
62 + NULL,
63 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
64 NGX_MODULE_V1_PADDING
65 };
66
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
67 @@ -51,6 +73,48 @@ static ngx_log_t ngx_log;
a65d8b3 Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add module config script
authored
71 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
72 +static ngx_string_to_macro_t ngx_syslog_facilities[] = {
73 + {ngx_string("auth"), LOG_AUTH},
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
74 +#if !(NGX_SOLARIS)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
75 + {ngx_string("authpriv"), LOG_AUTHPRIV},
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
76 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
77 + {ngx_string("cron"), LOG_CRON},
78 + {ngx_string("daemon"), LOG_DAEMON},
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
79 +#if !(NGX_SOLARIS)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
80 + {ngx_string("ftp"), LOG_FTP},
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
81 +#endif
a65d8b3 Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add module config script
authored
112 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
113
114 static ngx_str_t err_levels[] = {
115 ngx_null_string,
499309b Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
117 va_list args;
118 #endif
26b705a Weibin Yao(姚伟斌) add module config script
authored
119 u_char *p, *last, *msg;
120 +#if (NGX_ENABLE_SYSLOG)
121 + u_char *errstr_syslog;
122 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
123 u_char errstr[NGX_MAX_ERROR_STR];
124
26b705a Weibin Yao(姚伟斌) add module config script
authored
125 +#if !(NGX_ENABLE_SYSLOG)
126 if (log->file->fd == NGX_INVALID_FILE) {
127 return;
128 }
129 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
130
131 last = errstr + NGX_MAX_ERROR_STR;
132
499309b Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
134
135 p = errstr + ngx_cached_err_log_time.len;
136
26b705a Weibin Yao(姚伟斌) add module config script
authored
137 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
138 + errstr_syslog = p;
26b705a Weibin Yao(姚伟斌) add module config script
authored
139 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
140 +
141 p = ngx_slprintf(p, last, " [%V] ", &err_levels[level]);
142
143 /* pid#tid */
499309b Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
145
146 ngx_linefeed(p);
147
26b705a Weibin Yao(姚伟斌) add module config script
authored
148 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add module config script
authored
153 + /* Don't send the debug level info to syslog */
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
154 + if (log->syslog_on && level < NGX_LOG_DEBUG) {
155 + /* write to syslog */
1fe5833 Weibin Yao(姚伟斌) fix a bug of compile warning in amd64 server
authored
156 + syslog(log->priority, "%.*s", (int)(p - errstr_syslog), errstr_syslog);
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
157 + }
26b705a Weibin Yao(姚伟斌) add module config script
authored
158 +#else
159 (void) ngx_write_fd(log->file->fd, errstr, p - errstr);
160 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
161
162 if (!ngx_use_stderr
163 || level > NGX_LOG_WARN
26b705a Weibin Yao(姚伟斌) add module config script
authored
164 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
165 + || (log->file != NULL && log->file->fd == ngx_stderr))
26b705a Weibin Yao(姚伟斌) add module config script
authored
166 +#else
167 || log->file->fd == ngx_stderr)
168 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
169 {
170 return;
171 }
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
172 @@ -361,6 +450,50 @@ ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
173
26b705a Weibin Yao(姚伟斌) add module config script
authored
174 return log;
175 }
176 +
177 +
178 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add module config script
authored
219 +#endif
220
221
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
222 char *
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
223 @@ -421,6 +554,13 @@ static char *
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
224 ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
225 {
26b705a Weibin Yao(姚伟斌) add module config script
authored
226 ngx_str_t *value, name;
227 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
228 + u_char *off = NULL;
26b705a Weibin Yao(姚伟斌) add module config script
authored
229 + ngx_str_t priority;
230 +
231 + ngx_str_null(&name);
232 + ngx_str_null(&priority);
233 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
234
235 if (cf->cycle->new_log.file) {
236 return "is duplicate";
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
237 @@ -428,7 +568,44 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
238
239 value = cf->args->elts;
240
26b705a Weibin Yao(姚伟斌) add module config script
authored
241 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
242 + if (ngx_strncmp(value[1].data, "syslog", sizeof("syslog") - 1) == 0) {
28b0fee Weibin Yao(姚伟斌) add syslog_set
authored
243 + if (!cf->cycle->new_log.syslog_set) {
a65d8b3 Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add syslog_set
authored
249 + cf->cycle->new_log.syslog_on = 1;
250 +
a65d8b3 Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add module config script
authored
276 +#else
277 if (ngx_strcmp(value[1].data, "stderr") == 0) {
278 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
279 ngx_str_null(&name);
280
281 } else {
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
282 @@ -449,3 +626,63 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
283
284 return ngx_log_set_levels(cf, &cf->cycle->new_log);
285 }
286 +
287 +
26b705a Weibin Yao(姚伟斌) add module config script
authored
288 +#if (NGX_ENABLE_SYSLOG)
289 +
a65d8b3 Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add syslog_set
authored
302 + if (cf->cycle->new_log.syslog_set) {
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
303 + return "is duplicate";
304 + }
305 +
28b0fee Weibin Yao(姚伟斌) add syslog_set
authored
306 + cf->cycle->new_log.syslog_set = 1;
a65d8b3 Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add syslog_set
authored
340 + if (cycle->new_log.syslog_set) {
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
341 + closelog();
342 + }
343 +}
26b705a Weibin Yao(姚伟斌) add module config script
authored
344 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
345 +
346 diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h
28b0fee Weibin Yao(姚伟斌) add syslog_set
authored
347 index 1054836..14288ee 100644
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
348 --- a/src/core/ngx_log.h
349 +++ b/src/core/ngx_log.h
26b705a Weibin Yao(姚伟斌) add module config script
authored
350 @@ -11,6 +11,13 @@
3de3cbf Weibin Yao(姚伟斌) fix a bug of uninitlization of config with syslog
authored
351 #include <ngx_config.h>
352 #include <ngx_core.h>
26b705a Weibin Yao(姚伟斌) add module config script
authored
353
354 +#if (NGX_ENABLE_SYSLOG)
3de3cbf Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add module config script
authored
359 +#endif
360 +
3de3cbf Weibin Yao(姚伟斌) fix a bug of uninitlization of config with syslog
authored
361
362 #define NGX_LOG_STDERR 0
26b705a Weibin Yao(姚伟斌) add module config script
authored
363 #define NGX_LOG_EMERG 1
28b0fee Weibin Yao(姚伟斌) add syslog_set
authored
364 @@ -60,6 +67,13 @@ struct ngx_log_s {
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
365 */
366
367 char *action;
368 +
26b705a Weibin Yao(姚伟斌) add module config script
authored
369 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add syslog_set
authored
373 + unsigned syslog_set:1; /*unsigned :1 syslog_set */
26b705a Weibin Yao(姚伟斌) add module config script
authored
374 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
375 };
376
377
28b0fee Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add module config script
authored
382 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add module config script
authored
385 +#endif
a65d8b3 Weibin Yao(姚伟斌) 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
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
390 index 5f356c3..85a2964 100644
a65d8b3 Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add module config script
authored
393 @@ -8,6 +8,11 @@
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
394 #include <ngx_core.h>
395 #include <ngx_http.h>
396
26b705a Weibin Yao(姚伟斌) add module config script
authored
397 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
398 +#include <syslog.h>
399 +
400 +#define HTTP_SYSLOG_PRIORITY LOG_NOTICE
26b705a Weibin Yao(姚伟斌) add module config script
authored
401 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
402
403 typedef struct ngx_http_log_op_s ngx_http_log_op_t;
404
26b705a Weibin Yao(姚伟斌) add module config script
authored
405 @@ -51,6 +56,11 @@ typedef struct {
a65d8b3 Weibin Yao(姚伟斌) 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 Weibin Yao(姚伟斌) add module config script
authored
410 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
411 + ngx_int_t priority;
412 + unsigned syslog_on:1; /* unsigned :1 syslog_on */
26b705a Weibin Yao(姚伟斌) add module config script
authored
413 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
414 } ngx_http_log_t;
415
416
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
417 @@ -315,10 +325,26 @@ ngx_http_log_write(ngx_http_request_t *r, ngx_http_log_t *log, u_char *buf,
26b705a Weibin Yao(姚伟斌) add module config script
authored
418 ssize_t n;
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
419 ngx_err_t err;
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
420
26b705a Weibin Yao(姚伟斌) add module config script
authored
421 +#if (NGX_ENABLE_SYSLOG)
422 + n = 0;
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
423 + if (log->syslog_on) {
1fe5833 Weibin Yao(姚伟斌) fix a bug of compile warning in amd64 server
authored
424 + syslog(log->priority, "%.*s", (int)len, buf);
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
425 + }
26b705a Weibin Yao(姚伟斌) add module config script
authored
426 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
427 +
428 if (log->script == NULL) {
26b705a Weibin Yao(姚伟斌) add module config script
authored
429 name = log->file->name.data;
430 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
431 + if (name != NULL) {
432 + n = ngx_write_fd(log->file->fd, buf, len);
433 + }
0696171 Weibin Yao(姚伟斌) fix a bug of segment fault
authored
434 + else {
435 + n = len;
436 + }
26b705a Weibin Yao(姚伟斌) add module config script
authored
437 +#else
438 n = ngx_write_fd(log->file->fd, buf, len);
439
440 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
441 } else {
442 name = NULL;
443 n = ngx_http_log_script_write(r, log->script, &name, buf, len);
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
444 @@ -826,6 +852,10 @@ ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
26b705a Weibin Yao(姚伟斌) add module config script
authored
445 log->script = NULL;
3de3cbf Weibin Yao(姚伟斌) fix a bug of uninitlization of config with syslog
authored
446 log->disk_full_time = 0;
447 log->error_log_time = 0;
26b705a Weibin Yao(姚伟斌) add module config script
authored
448 +#if (NGX_ENABLE_SYSLOG)
3de3cbf Weibin Yao(姚伟斌) fix a bug of uninitlization of config with syslog
authored
449 + log->priority = HTTP_SYSLOG_PRIORITY;
450 + log->syslog_on = 0;
26b705a Weibin Yao(姚伟斌) add module config script
authored
451 +#endif
452
3de3cbf Weibin Yao(姚伟斌) fix a bug of uninitlization of config with syslog
authored
453 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module);
454 fmt = lmcf->formats.elts;
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
455 @@ -851,6 +881,13 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
456 ngx_http_log_main_conf_t *lmcf;
457 ngx_http_script_compile_t sc;
458
26b705a Weibin Yao(姚伟斌) add module config script
authored
459 +#if (NGX_ENABLE_SYSLOG)
460 + u_char *off;
461 + ngx_str_t priority;
462 + ngx_uint_t syslog_on = 0;
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
463 + name = priority = (ngx_str_t)ngx_null_string;
26b705a Weibin Yao(姚伟斌) add module config script
authored
464 +#endif
465 +
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
466 value = cf->args->elts;
467
468 if (ngx_strcmp(value[1].data, "off") == 0) {
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
469 @@ -863,6 +900,38 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
470 "invalid parameter \"%V\"", &value[2]);
471 return NGX_CONF_ERROR;
472 }
26b705a Weibin Yao(姚伟斌) add module config script
authored
473 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
474 + else if (ngx_strncmp(value[1].data, "syslog", sizeof("syslog") - 1) == 0) {
28b0fee Weibin Yao(姚伟斌) add syslog_set
authored
475 + if (!cf->cycle->new_log.syslog_set) {
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
476 + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
477 + "You must set the syslog directive and enable it first.");
478 + return NGX_CONF_ERROR;
479 + }
480 +
481 + syslog_on = 1;
482 + if (value[1].data[sizeof("syslog") - 1] == ':') {
483 + priority.len = value[1].len - sizeof("syslog");
484 + priority.data = value[1].data + sizeof("syslog");
485 +
486 + off = (u_char*) ngx_strchr(priority.data, '|');
487 + if (off != NULL) {
488 + priority.len = off - priority.data;
489 +
490 + off++;
491 + name.len = value[1].data + value[1].len - off;
492 + name.data = off;
493 + }
494 + }
495 + else {
496 + if (value[1].len > sizeof("syslog")) {
497 + name.len = value[1].len - sizeof("syslog");
498 + name.data = value[1].data + sizeof("syslog");
499 + }
500 + }
501 + } else {
502 + name = value[1];
503 + }
26b705a Weibin Yao(姚伟斌) add module config script
authored
504 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
505
506 if (llcf->logs == NULL) {
507 llcf->logs = ngx_array_create(cf->pool, 2, sizeof(ngx_http_log_t));
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
508 @@ -880,6 +949,52 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
509
510 ngx_memzero(log, sizeof(ngx_http_log_t));
511
26b705a Weibin Yao(姚伟斌) add module config script
authored
512 +#if (NGX_ENABLE_SYSLOG)
0696171 Weibin Yao(姚伟斌) fix a bug of segment fault
authored
513 + log->syslog_on = syslog_on;
26b705a Weibin Yao(姚伟斌) add module config script
authored
514 +
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
515 + if (priority.len == 0) {
516 + log->priority = HTTP_SYSLOG_PRIORITY;
517 + }
518 + else {
519 + log->priority = ngx_log_get_priority(cf, &priority);
520 + }
26b705a Weibin Yao(姚伟斌) add module config script
authored
521 +
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
522 + if (name.len != 0) {
523 + n = ngx_http_script_variables_count(&name);
26b705a Weibin Yao(姚伟斌) add module config script
authored
524 +
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
525 + if (n == 0) {
526 + log->file = ngx_conf_open_file(cf->cycle, &name);
527 + if (log->file == NULL) {
528 + return NGX_CONF_ERROR;
529 + }
530 + } else {
26b705a Weibin Yao(姚伟斌) add module config script
authored
531 + if (ngx_conf_full_name(cf->cycle, &name, 0) != NGX_OK) {
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
532 + return NGX_CONF_ERROR;
533 + }
534 + log->script = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_script_t));
535 + if (log->script == NULL) {
536 + return NGX_CONF_ERROR;
537 + }
538 + ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
539 + sc.cf = cf;
540 + sc.source = &name;
541 + sc.lengths = &log->script->lengths;
542 + sc.values = &log->script->values;
543 + sc.variables = n;
544 + sc.complete_lengths = 1;
545 + sc.complete_values = 1;
546 + if (ngx_http_script_compile(&sc) != NGX_OK) {
547 + return NGX_CONF_ERROR;
548 + }
549 + }
550 + }
551 + else {
552 + log->file = ngx_conf_open_file(cf->cycle, &name);
553 + if (log->file == NULL) {
26b705a Weibin Yao(姚伟斌) add module config script
authored
554 + return NGX_CONF_ERROR;
555 + }
556 + }
557 +#else
558 n = ngx_http_script_variables_count(&value[1]);
559
560 if (n == 0) {
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
561 @@ -887,7 +1002,7 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
26b705a Weibin Yao(姚伟斌) add module config script
authored
562 if (log->file == NULL) {
563 return NGX_CONF_ERROR;
564 }
565 -
566 +
567 } else {
568 if (ngx_conf_full_name(cf->cycle, &value[1], 0) != NGX_OK) {
569 return NGX_CONF_ERROR;
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
570 @@ -912,6 +1027,7 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
571 return NGX_CONF_ERROR;
572 }
573 }
26b705a Weibin Yao(姚伟斌) add module config script
authored
574 +#endif
575
576 if (cf->args->nelts >= 3) {
577 name = value[2];
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
578 diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
579 index 488688a..ca31cb2 100644
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
580 --- a/src/http/ngx_http_core_module.c
581 +++ b/src/http/ngx_http_core_module.c
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
582 @@ -1404,6 +1404,9 @@ ngx_http_update_location_config(ngx_http_request_t *r)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
583
584 if (r == r->main) {
585 r->connection->log->file = clcf->error_log->file;
26b705a Weibin Yao(姚伟斌) add module config script
authored
586 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
587 + r->connection->log->priority = clcf->error_log->priority;
26b705a Weibin Yao(姚伟斌) add module config script
authored
588 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
589
590 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
591 r->connection->log->log_level = clcf->error_log->log_level;
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
592 @@ -4259,17 +4262,72 @@ ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
26b705a Weibin Yao(姚伟斌) add module config script
authored
593
594 ngx_str_t *value;
595
596 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
597 + u_char *off = NULL;
598 + ngx_int_t syslog_on = 0;
599 + ngx_str_t name, priority;
26b705a Weibin Yao(姚伟斌) add module config script
authored
600 +
601 + name = priority = (ngx_str_t) ngx_null_string;
602 +#endif
603 +
604 if (clcf->error_log) {
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
605 return "is duplicate";
606 }
607
608 value = cf->args->elts;
609
26b705a Weibin Yao(姚伟斌) add module config script
authored
610 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
611 + if (ngx_strncmp(value[1].data, "syslog", sizeof("syslog") - 1) == 0) {
bfb8761 Weibin Yao(姚伟斌) fix a bug of config error with "error_log"
authored
612 + if (!cf->cycle->new_log.syslog_set) {
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
613 + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
614 + "You must set the syslog directive and enable it first.");
615 + return NGX_CONF_ERROR;
616 + }
617 +
618 + syslog_on = 1;
619 +
620 + if (value[1].data[sizeof("syslog") - 1] == ':') {
621 + priority.len = value[1].len - sizeof("syslog");
622 + priority.data = value[1].data + sizeof("syslog");
623 +
624 + off = (u_char*) ngx_strchr(priority.data, '|');
625 + if (off != NULL) {
626 + priority.len = off - priority.data;
627 +
628 + off++;
629 + name.len = value[1].data + value[1].len - off;
630 + name.data = off;
631 + }
632 + }
633 + else {
634 + if (value[1].len > sizeof("syslog")) {
635 + name.len = value[1].len - sizeof("syslog");
636 + name.data = value[1].data + sizeof("syslog");
637 + }
638 + }
639 + } else {
640 + name = value[1];
641 + }
642 +
643 + clcf->error_log = ngx_log_create(cf->cycle, &name);
26b705a Weibin Yao(姚伟斌) add module config script
authored
644 +#else
645 clcf->error_log = ngx_log_create(cf->cycle, &value[1]);
646 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
647 if (clcf->error_log == NULL) {
648 return NGX_CONF_ERROR;
649 }
650
26b705a Weibin Yao(姚伟斌) add module config script
authored
651 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
652 + if (syslog_on) {
653 + clcf->error_log->syslog_on = 1;
654 + if (ngx_log_set_priority(cf, &priority, clcf->error_log) == NGX_CONF_ERROR) {
655 + return NGX_CONF_ERROR;
656 + }
657 + }
658 +
26b705a Weibin Yao(姚伟斌) add module config script
authored
659 + clcf->error_log->log_level = 0;
660 +#endif
661 +
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
662 if (cf->args->nelts == 2) {
663 clcf->error_log->log_level = NGX_LOG_ERR;
664 return NGX_CONF_OK;
665 diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
666 index f1fab8a..4d9d604 100644
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
667 --- a/src/http/ngx_http_request.c
668 +++ b/src/http/ngx_http_request.c
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
669 @@ -428,6 +428,9 @@ ngx_http_init_request(ngx_event_t *rev)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
670
671 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
672 c->log->file = clcf->error_log->file;
26b705a Weibin Yao(姚伟斌) add module config script
authored
673 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
674 + c->log->priority = clcf->error_log->priority;
26b705a Weibin Yao(姚伟斌) add module config script
authored
675 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
676 if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
677 c->log->log_level = clcf->error_log->log_level;
678 }
499309b Weibin Yao(姚伟斌) add support for Solaris
authored
679 @@ -1759,6 +1762,9 @@ found:
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
680
681 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
682 r->connection->log->file = clcf->error_log->file;
26b705a Weibin Yao(姚伟斌) add module config script
authored
683 +#if (NGX_ENABLE_SYSLOG)
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
684 + r->connection->log->priority = clcf->error_log->priority;
26b705a Weibin Yao(姚伟斌) add module config script
authored
685 +#endif
a65d8b3 Weibin Yao(姚伟斌) add the 0.8.50 patch
authored
686
687 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
688 r->connection->log->log_level = clcf->error_log->log_level;
Something went wrong with that request. Please try again.