Permalink
Browse files

fix a bug of uninitlization of config with syslog

  • Loading branch information...
1 parent fb2799a commit 3de3cbf076cdb52f941a8b3363a5b8e44d4c6072 @yaoweibin committed May 3, 2011
Showing with 60 additions and 32 deletions.
  1. +60 −32 syslog_0.8.54.patch
View
@@ -1,18 +1,24 @@
+diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
+index 357c6b2..9540367 100644
+--- a/src/core/ngx_cycle.c
++++ b/src/core/ngx_cycle.c
+@@ -84,6 +84,9 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
+ cycle->pool = pool;
+ cycle->log = log;
+ cycle->new_log.log_level = NGX_LOG_ERR;
++ cycle->new_log.facility = SYSLOG_FACILITY;
++ cycle->new_log.priority = ERR_SYSLOG_PRIORITY;
++ cycle->new_log.syslog_on = 0;
+ cycle->old_cycle = old_cycle;
+
+ cycle->conf_prefix.len = old_cycle->conf_prefix.len;
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
-index c0485c6..97a4913 100644
+index c0485c6..c551248 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
-@@ -6,9 +6,22 @@
-
- #include <ngx_config.h>
- #include <ngx_core.h>
-+#include <syslog.h>
+@@ -9,6 +9,14 @@
-+#define SYSLOG_FACILITY LOG_LOCAL5
-+#define ERR_SYSLOG_PRIORITY LOG_ERR
-+
-+
static char *ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
+static char *ngx_set_syslog(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
+void log_exit(ngx_cycle_t *cycle);
@@ -25,7 +31,7 @@ index c0485c6..97a4913 100644
static ngx_command_t ngx_errlog_commands[] = {
-@@ -20,6 +33,13 @@ static ngx_command_t ngx_errlog_commands[] = {
+@@ -20,6 +28,13 @@ static ngx_command_t ngx_errlog_commands[] = {
0,
NULL},
@@ -39,7 +45,7 @@ index c0485c6..97a4913 100644
ngx_null_command
};
-@@ -42,7 +62,7 @@ ngx_module_t ngx_errlog_module = {
+@@ -42,7 +57,7 @@ ngx_module_t ngx_errlog_module = {
NULL, /* init thread */
NULL, /* exit thread */
NULL, /* exit process */
@@ -48,7 +54,7 @@ index c0485c6..97a4913 100644
NGX_MODULE_V1_PADDING
};
-@@ -51,6 +71,42 @@ static ngx_log_t ngx_log;
+@@ -51,6 +66,42 @@ static ngx_log_t ngx_log;
static ngx_open_file_t ngx_log_file;
ngx_uint_t ngx_use_stderr = 1;
@@ -91,7 +97,7 @@ index c0485c6..97a4913 100644
static ngx_str_t err_levels[] = {
ngx_null_string,
-@@ -87,12 +143,9 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
+@@ -87,12 +138,9 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
#if (NGX_HAVE_VARIADIC_MACROS)
va_list args;
#endif
@@ -105,7 +111,7 @@ index c0485c6..97a4913 100644
last = errstr + NGX_MAX_ERROR_STR;
-@@ -101,6 +154,8 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
+@@ -101,6 +149,8 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
p = errstr + ngx_cached_err_log_time.len;
@@ -114,7 +120,7 @@ index c0485c6..97a4913 100644
p = ngx_slprintf(p, last, " [%V] ", &err_levels[level]);
/* pid#tid */
-@@ -139,11 +194,19 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
+@@ -139,11 +189,19 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
ngx_linefeed(p);
@@ -136,7 +142,7 @@ index c0485c6..97a4913 100644
{
return;
}
-@@ -363,6 +426,48 @@ ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name)
+@@ -363,6 +421,48 @@ ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name)
}
@@ -185,7 +191,7 @@ index c0485c6..97a4913 100644
char *
ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log)
{
-@@ -420,7 +525,8 @@ ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log)
+@@ -420,7 +520,8 @@ ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log)
static char *
ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
@@ -195,7 +201,7 @@ index c0485c6..97a4913 100644
if (cf->cycle->new_log.file) {
return "is duplicate";
-@@ -428,7 +534,38 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+@@ -428,7 +529,38 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
value = cf->args->elts;
@@ -235,7 +241,7 @@ index c0485c6..97a4913 100644
ngx_str_null(&name);
} else {
-@@ -449,3 +586,60 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+@@ -449,3 +581,60 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return ngx_log_set_levels(cf, &cf->cycle->new_log);
}
@@ -297,10 +303,22 @@ index c0485c6..97a4913 100644
+}
+
diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h
-index 1054836..8353074 100644
+index 1054836..f280956 100644
--- a/src/core/ngx_log.h
+++ b/src/core/ngx_log.h
-@@ -60,6 +60,10 @@ struct ngx_log_s {
+@@ -10,6 +10,11 @@
+
+ #include <ngx_config.h>
+ #include <ngx_core.h>
++#include <syslog.h>
++
++
++#define SYSLOG_FACILITY LOG_LOCAL5
++#define ERR_SYSLOG_PRIORITY LOG_ERR
+
+
+ #define NGX_LOG_STDERR 0
+@@ -60,6 +65,10 @@ struct ngx_log_s {
*/
char *action;
@@ -311,7 +329,7 @@ index 1054836..8353074 100644
};
-@@ -197,6 +201,8 @@ void ngx_cdecl ngx_log_debug_core(ngx_log_t *log, ngx_err_t err,
+@@ -197,6 +206,8 @@ void ngx_cdecl ngx_log_debug_core(ngx_log_t *log, ngx_err_t err,
ngx_log_t *ngx_log_init(u_char *prefix);
ngx_log_t *ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name);
@@ -321,7 +339,7 @@ index 1054836..8353074 100644
void ngx_cdecl ngx_log_abort(ngx_err_t err, const char *fmt, ...);
void ngx_cdecl ngx_log_stderr(ngx_err_t err, const char *fmt, ...);
diff --git a/src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c
-index 5f356c3..a1eaa98 100644
+index 5f356c3..78589f1 100644
--- a/src/http/modules/ngx_http_log_module.c
+++ b/src/http/modules/ngx_http_log_module.c
@@ -8,6 +8,9 @@
@@ -370,7 +388,17 @@ index 5f356c3..a1eaa98 100644
} else {
name = NULL;
n = ngx_http_log_script_write(r, log->script, &name, buf, len);
-@@ -843,14 +858,16 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+@@ -827,6 +842,9 @@ ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
+ log->disk_full_time = 0;
+ log->error_log_time = 0;
+
++ log->priority = HTTP_SYSLOG_PRIORITY;
++ log->syslog_on = 0;
++
+ lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module);
+ fmt = lmcf->formats.elts;
+
+@@ -843,14 +861,16 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_log_loc_conf_t *llcf = conf;
@@ -389,7 +417,7 @@ index 5f356c3..a1eaa98 100644
value = cf->args->elts;
if (ngx_strcmp(value[1].data, "off") == 0) {
-@@ -863,6 +880,36 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+@@ -863,6 +883,36 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
"invalid parameter \"%V\"", &value[2]);
return NGX_CONF_ERROR;
}
@@ -426,29 +454,29 @@ index 5f356c3..a1eaa98 100644
if (llcf->logs == NULL) {
llcf->logs = ngx_array_create(cf->pool, 2, sizeof(ngx_http_log_t));
-@@ -880,35 +927,48 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+@@ -880,35 +930,48 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_memzero(log, sizeof(ngx_http_log_t));
- n = ngx_http_script_variables_count(&value[1]);
-
+-
- if (n == 0) {
- log->file = ngx_conf_open_file(cf->cycle, &value[1]);
- if (log->file == NULL) {
- return NGX_CONF_ERROR;
- }
-+ log->syslog_on = syslog_on;
-
+-
- } else {
- if (ngx_conf_full_name(cf->cycle, &value[1], 0) != NGX_OK) {
- return NGX_CONF_ERROR;
- }
--
+
- log->script = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_script_t));
- if (log->script == NULL) {
- return NGX_CONF_ERROR;
- }
--
++ log->syslog_on = syslog_on;
+
- ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
+ if (priority.len == 0) {
+ log->priority = HTTP_SYSLOG_PRIORITY;

0 comments on commit 3de3cbf

Please sign in to comment.