diff options
Diffstat (limited to 'src/http')
| -rw-r--r-- | src/http/modules/ngx_http_charset_filter.c | 10 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_index_handler.c | 18 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_log_handler.c | 73 | ||||
| -rw-r--r-- | src/http/ngx_http.c | 25 | ||||
| -rw-r--r-- | src/http/ngx_http_config.h | 12 | ||||
| -rw-r--r-- | src/http/ngx_http_core_module.c | 114 | ||||
| -rw-r--r-- | src/http/ngx_http_event.c | 32 | ||||
| -rw-r--r-- | src/http/ngx_http_get_time.c | 2 | ||||
| -rw-r--r-- | src/http/ngx_http_output_filter.c | 10 | ||||
| -rw-r--r-- | src/http/ngx_http_write_filter.c | 10 |
10 files changed, 158 insertions, 148 deletions
diff --git a/src/http/modules/ngx_http_charset_filter.c b/src/http/modules/ngx_http_charset_filter.c index 50642ef9e..ecc66b4f1 100644 --- a/src/http/modules/ngx_http_charset_filter.c +++ b/src/http/modules/ngx_http_charset_filter.c @@ -10,8 +10,8 @@ typedef struct { static int ngx_http_charset_filter_init(ngx_cycle_t *cycle); -static void *ngx_http_charset_create_loc_conf(ngx_pool_t *pool); -static char *ngx_http_charset_merge_loc_conf(ngx_pool_t *pool, +static void *ngx_http_charset_create_loc_conf(ngx_conf_t *cf); +static char *ngx_http_charset_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child); @@ -100,19 +100,19 @@ static int ngx_http_charset_filter_init(ngx_cycle_t *cycle) } -static void *ngx_http_charset_create_loc_conf(ngx_pool_t *pool) +static void *ngx_http_charset_create_loc_conf(ngx_conf_t *cf) { ngx_http_charset_loc_conf_t *lcf; ngx_test_null(lcf, - ngx_pcalloc(pool, sizeof(ngx_http_charset_loc_conf_t)), + ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_loc_conf_t)), NGX_CONF_ERROR); return lcf; } -static char *ngx_http_charset_merge_loc_conf(ngx_pool_t *pool, +static char *ngx_http_charset_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) { ngx_http_charset_loc_conf_t *prev = parent; diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c index c6c111716..7c348e2ad 100644 --- a/src/http/modules/ngx_http_index_handler.c +++ b/src/http/modules/ngx_http_index_handler.c @@ -15,11 +15,11 @@ typedef struct { static int ngx_http_index_test_dir(ngx_http_request_t *r); static int ngx_http_index_init(ngx_cycle_t *cycle); -static void *ngx_http_index_create_conf(ngx_pool_t *pool); -static char *ngx_http_index_merge_conf(ngx_pool_t *p, void *parent, - void *child); +static void *ngx_http_index_create_conf(ngx_conf_t *cf); +static char *ngx_http_index_merge_conf(ngx_conf_t *cf, + void *parent, void *child); static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static ngx_command_t ngx_http_index_commands[] = { @@ -220,14 +220,15 @@ static int ngx_http_index_init(ngx_cycle_t *cycle) } -static void *ngx_http_index_create_conf(ngx_pool_t *pool) +static void *ngx_http_index_create_conf(ngx_conf_t *cf) { ngx_http_index_conf_t *conf; - ngx_test_null(conf, ngx_palloc(pool, sizeof(ngx_http_index_conf_t)), + ngx_test_null(conf, ngx_palloc(cf->pool, sizeof(ngx_http_index_conf_t)), NGX_CONF_ERROR); - ngx_init_array(conf->indices, pool, 3, sizeof(ngx_str_t), NGX_CONF_ERROR); + ngx_init_array(conf->indices, cf->pool, 3, sizeof(ngx_str_t), + NGX_CONF_ERROR); conf->max_index_len = 0; return conf; @@ -236,7 +237,8 @@ static void *ngx_http_index_create_conf(ngx_pool_t *pool) /* TODO: remove duplicate indices */ -static char *ngx_http_index_merge_conf(ngx_pool_t *p, void *parent, void *child) +static char *ngx_http_index_merge_conf(ngx_conf_t *cf, + void *parent, void *child) { ngx_http_index_conf_t *prev = parent; ngx_http_index_conf_t *conf = child; diff --git a/src/http/modules/ngx_http_log_handler.c b/src/http/modules/ngx_http_log_handler.c index c186ac904..759ac763e 100644 --- a/src/http/modules/ngx_http_log_handler.c +++ b/src/http/modules/ngx_http_log_handler.c @@ -5,14 +5,14 @@ typedef struct { - ngx_file_t file; + ngx_open_file_t *file; } ngx_http_log_conf_t; -static void *ngx_http_log_create_conf(ngx_pool_t *pool); -static char *ngx_http_log_merge_conf(ngx_pool_t *p, void *parent, void *child); +static void *ngx_http_log_create_conf(ngx_conf_t *cf); +static char *ngx_http_log_merge_conf(ngx_conf_t *cf, void *parent, void *child); static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static ngx_command_t ngx_http_log_commands[] = { @@ -49,6 +49,8 @@ ngx_module_t ngx_http_log_module = { }; +static ngx_str_t http_access_log = ngx_string("access.log"); + static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; @@ -60,6 +62,9 @@ int ngx_http_log_handler(ngx_http_request_t *r) size_t len; ngx_tm_t tm; ngx_http_log_conf_t *lcf; +#if (WIN32) + int written; +#endif ngx_log_debug(r->connection->log, "log handler"); @@ -135,35 +140,47 @@ int ngx_http_log_handler(ngx_http_request_t *r) *p++ = '"'; #if (WIN32) + *p++ = CR; *p++ = LF; + WriteFile(lcf->file->fd, line, p - line, &written, NULL); + #else + *p++ = LF; + write(lcf->file->fd, line, p - line); + #endif - write(lcf->file.fd, line, p - line); return NGX_OK; } -static void *ngx_http_log_create_conf(ngx_pool_t *pool) +static void *ngx_http_log_create_conf(ngx_conf_t *cf) { ngx_http_log_conf_t *conf; - ngx_test_null(conf, ngx_pcalloc(pool, sizeof(ngx_http_log_conf_t)), + ngx_test_null(conf, ngx_pcalloc(cf->pool, sizeof(ngx_http_log_conf_t)), NGX_CONF_ERROR); return conf; } -static char *ngx_http_log_merge_conf(ngx_pool_t *p, void *parent, void *child) +static char *ngx_http_log_merge_conf(ngx_conf_t *cf, void *parent, void *child) { ngx_http_log_conf_t *prev = parent; ngx_http_log_conf_t *conf = child; - /* STUB */ - *conf = *prev; + if (conf->file == NULL) { + if (prev->file) { + conf->file = prev->file; + } else { + ngx_test_null(conf->file, + ngx_conf_open_file(cf->cycle, &http_access_log), + NGX_CONF_ERROR); + } + } return NGX_CONF_OK; } @@ -174,44 +191,12 @@ static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, { ngx_http_log_conf_t *lcf = conf; - int len; - ngx_err_t err; ngx_str_t *value; value = cf->args->elts; - lcf->file.name.len = value[1].len; - lcf->file.name.data = value[1].data; - - lcf->file.fd = ngx_open_file(lcf->file.name.data, - NGX_FILE_RDWR, - NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); - - if (lcf->file.fd == NGX_INVALID_FILE) { - err = ngx_errno; - len = ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1, - ngx_open_file_n " \"%s\" failed (%d: ", - lcf->file.name.data, err); - len += ngx_strerror_r(err, ngx_conf_errstr + len, - sizeof(ngx_conf_errstr) - len - 1); - ngx_conf_errstr[len++] = ')'; - ngx_conf_errstr[len++] = '\0'; - return ngx_conf_errstr; - } - -#if (WIN32) - if (ngx_file_append_mode(lcf->file.fd) == NGX_ERROR) { - err = ngx_errno; - len = ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1, - ngx_file_append_mode_n " \"%s\" failed (%d: ", - lcf->file.name.data, err); - len += ngx_strerror_r(err, ngx_conf_errstr + len, - sizeof(ngx_conf_errstr) - len - 1); - ngx_conf_errstr[len++] = ')'; - ngx_conf_errstr[len++] = '\0'; - return ngx_conf_errstr; - } -#endif + ngx_test_null(lcf->file, ngx_conf_open_file(cf->cycle, &value[1]), + NGX_CONF_ERROR); return NGX_CONF_OK; } diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c index 945502669..551a1e810 100644 --- a/src/http/ngx_http.c +++ b/src/http/ngx_http.c @@ -56,7 +56,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) ngx_http_in_addr_t *in_addr, *inaddr; ngx_http_core_main_conf_t *cmcf; ngx_http_core_srv_conf_t **cscfp, *cscf; - ngx_http_core_loc_conf_t **clcfp; + ngx_http_core_loc_conf_t **clcfp, *clcf; ngx_http_listen_t *lscf; ngx_http_server_name_t *s_name, *name; #if (WIN32) @@ -108,20 +108,17 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) mi = ngx_modules[m]->ctx_index; if (module->create_main_conf) { - ngx_test_null(ctx->main_conf[mi], - module->create_main_conf(cf->pool), + ngx_test_null(ctx->main_conf[mi], module->create_main_conf(cf), NGX_CONF_ERROR); } if (module->create_srv_conf) { - ngx_test_null(ctx->srv_conf[mi], - module->create_srv_conf(cf->pool), + ngx_test_null(ctx->srv_conf[mi], module->create_srv_conf(cf), NGX_CONF_ERROR); } if (module->create_loc_conf) { - ngx_test_null(ctx->loc_conf[mi], - module->create_loc_conf(cf->pool), + ngx_test_null(ctx->loc_conf[mi], module->create_loc_conf(cf), NGX_CONF_ERROR); } } @@ -157,7 +154,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) /* init http{} main_conf's */ if (module->init_main_conf) { - rv = module->init_main_conf(cf->pool, ctx->main_conf[mi]); + rv = module->init_main_conf(cf, ctx->main_conf[mi]); if (rv != NGX_CONF_OK) { return rv; } @@ -168,7 +165,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) /* merge the server{}s' srv_conf's */ if (module->merge_srv_conf) { - rv = module->merge_srv_conf(cf->pool, + rv = module->merge_srv_conf(cf, ctx->srv_conf[mi], cscfp[s]->ctx->srv_conf[mi]); if (rv != NGX_CONF_OK) { @@ -180,7 +177,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) /* merge the server{}'s loc_conf */ - rv = module->merge_loc_conf(cf->pool, + rv = module->merge_loc_conf(cf, ctx->loc_conf[mi], cscfp[s]->ctx->loc_conf[mi]); if (rv != NGX_CONF_OK) { @@ -192,7 +189,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) clcfp = (ngx_http_core_loc_conf_t **)cscfp[s]->locations.elts; for (l = 0; l < cscfp[s]->locations.nelts; l++) { - rv = module->merge_loc_conf(cf->pool, + rv = module->merge_loc_conf(cf, cscfp[s]->ctx->loc_conf[mi], clcfp[l]->loc_conf[mi]); if (rv != NGX_CONF_OK) { @@ -464,12 +461,18 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) ls->nonblocking = 1; ls->handler = ngx_http_init_connection; + +#if 0 ls->log = cf->cycle->log; +#endif cscf = in_addr[a].core_srv_conf; ls->pool_size = cscf->connection_pool_size; ls->post_accept_timeout = cscf->post_accept_timeout; + clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index]; + ls->log = clcf->err_log; + #if (WIN32) iocpcf = ngx_event_get_conf(cf->cycle->conf_ctx, ngx_iocp_module); if (iocpcf->acceptex_read) { diff --git a/src/http/ngx_http_config.h b/src/http/ngx_http_config.h index 50804c3a6..9d200c448 100644 --- a/src/http/ngx_http_config.h +++ b/src/http/ngx_http_config.h @@ -20,14 +20,14 @@ typedef struct { typedef struct { - void *(*create_main_conf)(ngx_pool_t *p); - char *(*init_main_conf)(ngx_pool_t *p, void *conf); + void *(*create_main_conf)(ngx_conf_t *cf); + char *(*init_main_conf)(ngx_conf_t *cf, void *conf); - void *(*create_srv_conf)(ngx_pool_t *p); - char *(*merge_srv_conf)(ngx_pool_t *p, void *prev, void *conf); + void *(*create_srv_conf)(ngx_conf_t *cf); + char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev, void *conf); - void *(*create_loc_conf)(ngx_pool_t *p); - char *(*merge_loc_conf)(ngx_pool_t *p, void *prev, void *conf); + void *(*create_loc_conf)(ngx_conf_t *cf); + char *(*merge_loc_conf)(ngx_conf_t *cf, void *prev, void *conf); } ngx_http_module_t; diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index aa3c58280..a895fbd6c 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -11,25 +11,26 @@ int ngx_http_static_handler(ngx_http_request_t *r); static int ngx_http_core_index_handler(ngx_http_request_t *r); -static void *ngx_http_core_create_main_conf(ngx_pool_t *pool); -static char *ngx_http_core_init_main_conf(ngx_pool_t *pool, void *conf); -static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool); -static char *ngx_http_core_merge_srv_conf(ngx_pool_t *pool, +static void *ngx_http_core_create_main_conf(ngx_conf_t *cf); +static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf); +static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf); +static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child); -static void *ngx_http_core_create_loc_conf(ngx_pool_t *pool); -static char *ngx_http_core_merge_loc_conf(ngx_pool_t *pool, +static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf); +static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child); static int ngx_http_core_init(ngx_cycle_t *cycle); static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy); static int ngx_cmp_locations(const void *first, const void *second); static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, - void *dummy); + void *dummy); static char *ngx_types_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf); static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); +static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static ngx_command_t ngx_http_core_commands[] = { @@ -165,6 +166,13 @@ static ngx_command_t ngx_http_core_commands[] = { offsetof(ngx_http_core_loc_conf_t, lingering_timeout), NULL}, + {ngx_string("error_log"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, + ngx_set_error_log, + NGX_HTTP_LOC_CONF_OFFSET, + 0, + NULL}, + ngx_null_command }; @@ -226,22 +234,25 @@ void ngx_http_handler(ngx_http_request_t *r) #if 0 ngx_log_debug(r->connection->log, "trans: %s" _ clcfp[i]->name.data); #endif - if (r->uri.len < clcfp[i]->name.len) { - continue; - } + if (r->uri.len < clcfp[i]->name.len) { + continue; + } - rc = ngx_strncmp(r->uri.data, clcfp[i]->name.data, - clcfp[i]->name.len); + rc = ngx_strncmp(r->uri.data, clcfp[i]->name.data, + clcfp[i]->name.len); ngx_log_debug(r->connection->log, "rc: %d" _ rc); - if (rc < 0) { - break; - } + if (rc < 0) { + break; + } - if (rc == 0) { - r->loc_conf = clcfp[i]->loc_conf; - } + if (rc == 0) { + r->loc_conf = clcfp[i]->loc_conf; + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); + r->connection->log->file = clcf->err_log->file; + r->connection->log->log_level = clcf->err_log->log_level; + } } clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); @@ -583,13 +594,13 @@ static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) if (module->create_srv_conf) { ngx_test_null(ctx->srv_conf[ngx_modules[m]->ctx_index], - module->create_srv_conf(cf->pool), + module->create_srv_conf(cf), NGX_CONF_ERROR); } if (module->create_loc_conf) { ngx_test_null(ctx->loc_conf[ngx_modules[m]->ctx_index], - module->create_loc_conf(cf->pool), + module->create_loc_conf(cf), NGX_CONF_ERROR); } } @@ -664,7 +675,7 @@ static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) if (module->create_loc_conf) { ngx_test_null(ctx->loc_conf[ngx_modules[m]->ctx_index], - module->create_loc_conf(cf->pool), + module->create_loc_conf(cf), NGX_CONF_ERROR); } } @@ -740,22 +751,23 @@ static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) } -static void *ngx_http_core_create_main_conf(ngx_pool_t *pool) +static void *ngx_http_core_create_main_conf(ngx_conf_t *cf) { ngx_http_core_main_conf_t *cmcf; ngx_test_null(cmcf, - ngx_palloc(pool, sizeof(ngx_http_core_main_conf_t)), + ngx_palloc(cf->pool, sizeof(ngx_http_core_main_conf_t)), NGX_CONF_ERROR); - ngx_init_array(cmcf->servers, pool, 5, sizeof(ngx_http_core_srv_conf_t *), + ngx_init_array(cmcf->servers, cf->pool, + 5, sizeof(ngx_http_core_srv_conf_t *), NGX_CONF_ERROR); return cmcf; } -static char *ngx_http_core_init_main_conf(ngx_pool_t *pool, void *conf) +static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf) { ngx_http_core_main_conf_t *cmcf = conf; @@ -765,19 +777,20 @@ static char *ngx_http_core_init_main_conf(ngx_pool_t *pool, void *conf) } -static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool) +static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf) { ngx_http_core_srv_conf_t *cscf; ngx_test_null(cscf, - ngx_pcalloc(pool, sizeof(ngx_http_core_srv_conf_t)), + ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t)), NGX_CONF_ERROR); - ngx_init_array(cscf->locations, pool, 5, sizeof(void *), NGX_CONF_ERROR); - ngx_init_array(cscf->listen, pool, 5, sizeof(ngx_http_listen_t), - NGX_CONF_ERROR); - ngx_init_array(cscf->server_names, pool, 5, sizeof(ngx_http_server_name_t), + ngx_init_array(cscf->locations, cf->pool, + 5, sizeof(void *), NGX_CONF_ERROR); + ngx_init_array(cscf->listen, cf->pool, 5, sizeof(ngx_http_listen_t), NGX_CONF_ERROR); + ngx_init_array(cscf->server_names, cf->pool, + 5, sizeof(ngx_http_server_name_t), NGX_CONF_ERROR); cscf->connection_pool_size = NGX_CONF_UNSET; cscf->post_accept_timeout = NGX_CONF_UNSET; @@ -790,14 +803,12 @@ static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool) } -static char *ngx_http_core_merge_srv_conf(ngx_pool_t *pool, +static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) { ngx_http_core_srv_conf_t *prev = parent; ngx_http_core_srv_conf_t *conf = child; - int len; - ngx_err_t err; ngx_http_listen_t *l; ngx_http_server_name_t *n; @@ -817,24 +828,13 @@ static char *ngx_http_core_merge_srv_conf(ngx_pool_t *pool, if (conf->server_names.nelts == 0) { ngx_test_null(n, ngx_push_array(&conf->server_names), NGX_CONF_ERROR); - ngx_test_null(n->name.data, ngx_palloc(pool, NGX_MAXHOSTNAMELEN), + ngx_test_null(n->name.data, ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN), NGX_CONF_ERROR); if (gethostname(n->name.data, NGX_MAXHOSTNAMELEN) == -1) { -#if 0 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, "gethostname() failed"); return NGX_CONF_ERROR; -#endif - - err = ngx_errno; - len = ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1, - "gethostname() failed (%d: ", err); - len += ngx_strerror_r(err, ngx_conf_errstr + len, - sizeof(ngx_conf_errstr) - len - 1); - ngx_conf_errstr[len++] = ')'; - ngx_conf_errstr[len++] = '\0'; - return ngx_conf_errstr; } n->name.len = ngx_strlen(n->name.data); @@ -858,12 +858,12 @@ static char *ngx_http_core_merge_srv_conf(ngx_pool_t *pool, } -static void *ngx_http_core_create_loc_conf(ngx_pool_t *pool) +static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf) { ngx_http_core_loc_conf_t *lcf; ngx_test_null(lcf, - ngx_pcalloc(pool, sizeof(ngx_http_core_loc_conf_t)), + ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)), NGX_CONF_ERROR); /* set by ngx_pcalloc(): @@ -897,7 +897,7 @@ static ngx_http_type_t default_types[] = { }; -static char *ngx_http_core_merge_loc_conf(ngx_pool_t *pool, +static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) { ngx_http_core_loc_conf_t *prev = parent; @@ -914,13 +914,13 @@ static char *ngx_http_core_merge_loc_conf(ngx_pool_t *pool, } else { ngx_test_null(conf->types, - ngx_palloc(pool, NGX_HTTP_TYPES_HASH_PRIME + ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME * sizeof(ngx_array_t)), NGX_CONF_ERROR); for (i = 0; i < NGX_HTTP_TYPES_HASH_PRIME; i++) { - ngx_init_array(conf->types[i], pool, 5, sizeof(ngx_http_type_t), - NGX_CONF_ERROR); + ngx_init_array(conf->types[i], cf->pool, + 5, sizeof(ngx_http_type_t), NGX_CONF_ERROR); } for (i = 0; default_types[i].exten.len; i++) { @@ -936,6 +936,14 @@ static char *ngx_http_core_merge_loc_conf(ngx_pool_t *pool, } } + if (conf->err_log == NULL) { + if (prev->err_log) { + conf->err_log = prev->err_log; + } else { + conf->err_log = cf->cycle->log; + } + } + ngx_conf_merge_str_value(conf->default_type, prev->default_type, "text/plain"); diff --git a/src/http/ngx_http_event.c b/src/http/ngx_http_event.c index 5531bac16..e129a6d5a 100644 --- a/src/http/ngx_http_event.c +++ b/src/http/ngx_http_event.c @@ -65,7 +65,7 @@ void ngx_http_init_connection(ngx_connection_t *c) { int event; ngx_event_t *rev; - ngx_http_log_ctx_t *lcx; + ngx_http_log_ctx_t *lctx; c->addr_text.data = ngx_palloc(c->pool, c->listening->addr_text_max_len); if (c->addr_text.data == NULL) { @@ -81,15 +81,15 @@ void ngx_http_init_connection(ngx_connection_t *c) return; } - lcx = ngx_pcalloc(c->pool, sizeof(ngx_http_log_ctx_t)); - if (lcx == NULL) { + lctx = ngx_pcalloc(c->pool, sizeof(ngx_http_log_ctx_t)); + if (lctx == NULL) { ngx_http_close_connection(c); return; } - lcx->client = c->addr_text.data; - lcx->action = "reading client request line"; - c->log->data = lcx; + lctx->client = c->addr_text.data; + lctx->action = "reading client request line"; + c->log->data = lctx; c->log->handler = ngx_http_log_error; rev = c->read; @@ -136,6 +136,7 @@ static void ngx_http_init_request(ngx_event_t *rev) ngx_http_in_addr_t *in_addr; ngx_http_server_name_t *server_name; ngx_http_core_srv_conf_t *cscf; + ngx_http_core_loc_conf_t *clcf; c = rev->data; @@ -212,6 +213,10 @@ ngx_log_debug(rev->log, "IN: %08x" _ in_port); server_name = cscf->server_names.elts; r->server_name = &server_name->name; + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); + c->log->file = clcf->err_log->file; + c->log->log_level = clcf->err_log->log_level; + if (c->buffer == NULL) { c->buffer = ngx_create_temp_hunk(c->pool, cscf->client_header_buffer_size, @@ -265,7 +270,7 @@ static void ngx_http_process_request_line(ngx_event_t *rev) ssize_t n; ngx_connection_t *c; ngx_http_request_t *r; - ngx_http_log_ctx_t *lcx; + ngx_http_log_ctx_t *lctx; ngx_http_core_srv_conf_t *cscf; c = rev->data; @@ -421,9 +426,9 @@ static void ngx_http_process_request_line(ngx_event_t *rev) return; } - lcx = c->log->data; - lcx->action = "reading client request headers"; - lcx->url = r->unparsed_uri.data; + lctx = c->log->data; + lctx->action = "reading client request headers"; + lctx->url = r->unparsed_uri.data; r->headers_in.headers = ngx_create_table(r->pool, 10); if (cscf->large_client_header @@ -505,6 +510,7 @@ static void ngx_http_process_request_headers(ngx_event_t *rev) ngx_http_request_t *r; ngx_http_server_name_t *name; ngx_http_core_srv_conf_t *cscf; + ngx_http_core_loc_conf_t *clcf; c = rev->data; r = c->data; @@ -619,6 +625,12 @@ static void ngx_http_process_request_headers(ngx_event_t *rev) { r->srv_conf = name[i].core_srv_conf->ctx->srv_conf; r->loc_conf = name[i].core_srv_conf->ctx->loc_conf; + + clcf = ngx_http_get_module_loc_conf(r, + ngx_http_core_module); + c->log->file = clcf->err_log->file; + c->log->log_level = clcf->err_log->log_level; + break; } } diff --git a/src/http/ngx_http_get_time.c b/src/http/ngx_http_get_time.c index 45df008d1..971914e4d 100644 --- a/src/http/ngx_http_get_time.c +++ b/src/http/ngx_http_get_time.c @@ -5,7 +5,7 @@ size_t ngx_http_get_time(char *buf, time_t t) { - struct tm *tp; + struct tm *tp; tp = gmtime(&t); return strftime(buf, 30, "%a, %d %b %Y %H:%M:%S GMT", tp); diff --git a/src/http/ngx_http_output_filter.c b/src/http/ngx_http_output_filter.c index dbc56def5..6e1d9d388 100644 --- a/src/http/ngx_http_output_filter.c +++ b/src/http/ngx_http_output_filter.c @@ -18,8 +18,8 @@ typedef struct { static int ngx_http_output_filter_copy_hunk(ngx_hunk_t *dst, ngx_hunk_t *src); -static void *ngx_http_output_filter_create_conf(ngx_pool_t *pool); -static char *ngx_http_output_filter_merge_conf(ngx_pool_t *pool, +static void *ngx_http_output_filter_create_conf(ngx_conf_t *cf); +static char *ngx_http_output_filter_merge_conf(ngx_conf_t *cf, void *parent, void *child); @@ -307,12 +307,12 @@ ngx_log_debug(src->file->log, "READ: %qd:%qd %X:%X %X:%X" _ } -static void *ngx_http_output_filter_create_conf(ngx_pool_t *pool) +static void *ngx_http_output_filter_create_conf(ngx_conf_t *cf) { ngx_http_output_filter_conf_t *conf; ngx_test_null(conf, - ngx_palloc(pool, sizeof(ngx_http_output_filter_conf_t)), + ngx_palloc(cf->pool, sizeof(ngx_http_output_filter_conf_t)), NULL); conf->hunk_size = NGX_CONF_UNSET; @@ -321,7 +321,7 @@ static void *ngx_http_output_filter_create_conf(ngx_pool_t *pool) } -static char *ngx_http_output_filter_merge_conf(ngx_pool_t *pool, +static char *ngx_http_output_filter_merge_conf(ngx_conf_t *cf, void *parent, void *child) { ngx_http_output_filter_conf_t *prev = parent; diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c index 1a9f9284b..26c632c62 100644 --- a/src/http/ngx_http_write_filter.c +++ b/src/http/ngx_http_write_filter.c @@ -15,8 +15,8 @@ typedef struct { } ngx_http_write_filter_ctx_t; -static void *ngx_http_write_filter_create_conf(ngx_pool_t *pool); -static char *ngx_http_write_filter_merge_conf(ngx_pool_t *pool, +static void *ngx_http_write_filter_create_conf(ngx_conf_t *cf); +static char *ngx_http_write_filter_merge_conf(ngx_conf_t *cf, void *parent, void *child); static int ngx_http_write_filter_init(ngx_cycle_t *cycle); @@ -162,12 +162,12 @@ int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) } -static void *ngx_http_write_filter_create_conf(ngx_pool_t *pool) +static void *ngx_http_write_filter_create_conf(ngx_conf_t *cf) { ngx_http_write_filter_conf_t *conf; ngx_test_null(conf, - ngx_palloc(pool, sizeof(ngx_http_write_filter_conf_t)), + ngx_palloc(cf->pool, sizeof(ngx_http_write_filter_conf_t)), NULL); conf->buffer_output = NGX_CONF_UNSET; @@ -176,7 +176,7 @@ static void *ngx_http_write_filter_create_conf(ngx_pool_t *pool) } -static char *ngx_http_write_filter_merge_conf(ngx_pool_t *pool, +static char *ngx_http_write_filter_merge_conf(ngx_conf_t *cf, void *parent, void *child) { ngx_http_write_filter_conf_t *prev = parent; |
