# HG changeset patch # User Igor Sysoev # Date 1057936670 0 # Node ID f6e3c5d019b6dcab636e97590ef71c3f8a5102f5 # Parent 571bcbff82c50d2d3b366a1a08a4a365151a1855 nginx-0.0.1-2003-07-11-19:17:50 import diff --git a/src/core/nginx.c b/src/core/nginx.c --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -9,10 +9,42 @@ static ngx_cycle_t *ngx_init_cycle(ngx_c static int ngx_open_listening_sockets(ngx_cycle_t *cycle, ngx_log_t *log); static void ngx_clean_old_cycles(ngx_event_t *ev); + #if (NGX_DEBUG) && (__FreeBSD__) extern char *malloc_options; #endif + +typedef struct { + int daemon; +} ngx_core_conf_t; + + +static ngx_str_t core_name = ngx_string("core"); + +static ngx_command_t ngx_core_commands[] = { + + {ngx_string("daemon"), + NGX_MAIN_CONF|NGX_CONF_TAKE1, + ngx_conf_set_core_flag_slot, + 0, + offsetof(ngx_core_conf_t, daemon), + NULL}, + + ngx_null_command +}; + + +ngx_module_t ngx_core_module = { + NGX_MODULE, + &core_name, /* module context */ + ngx_core_commands, /* module directives */ + NGX_CORE_MODULE, /* module type */ + NULL, /* init module */ + NULL /* init child */ +}; + + int ngx_max_module; ngx_os_io_t ngx_io; @@ -33,9 +65,10 @@ int rotate; int main(int argc, char *const *argv) { - int i; - ngx_log_t *log; - ngx_cycle_t *cycle; + int i; + ngx_log_t *log; + ngx_cycle_t *cycle; + ngx_core_conf_t *ccf; #if (NGX_DEBUG) && (__FreeBSD__) malloc_options = "J"; @@ -63,14 +96,18 @@ int main(int argc, char *const *argv) #if !(WIN32) - if (0) { - if (ngx_daemon(cycle->log) == NGX_ERROR) { + ccf = (ngx_core_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx, + ngx_core_module); + + if (ccf->daemon != 0) { + if (ngx_daemon(ngx_cycle->log) == NGX_ERROR) { return 1; } } - if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) { - ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "dup2(STDERR) failed"); + if (dup2(ngx_cycle->log->file->fd, STDERR_FILENO) == -1) { + ngx_log_error(NGX_LOG_EMERG, ngx_cycle->log, ngx_errno, + "dup2(STDERR) failed"); return 1; } @@ -138,6 +175,7 @@ static ngx_cycle_t *ngx_init_cycle(ngx_c ngx_conf_t conf; ngx_pool_t *pool; ngx_cycle_t *cycle, **old; + ngx_core_conf_t *ccf; ngx_open_file_t *file; ngx_listening_t *ls, *nls; @@ -156,6 +194,7 @@ static ngx_cycle_t *ngx_init_cycle(ngx_c cycle->old_cycle = old_cycle; + n = old_cycle ? old_cycle->open_files.nelts : 20; cycle->open_files.elts = ngx_pcalloc(pool, n * sizeof(ngx_open_file_t)); if (cycle->open_files.elts == NULL) { @@ -167,12 +206,14 @@ static ngx_cycle_t *ngx_init_cycle(ngx_c cycle->open_files.nalloc = n; cycle->open_files.pool = pool; + cycle->log = ngx_log_create_errlog(cycle, NULL); if (cycle->log == NULL) { ngx_destroy_pool(pool); return NULL; } + n = old_cycle ? old_cycle->listening.nelts : 10; cycle->listening.elts = ngx_pcalloc(pool, n * sizeof(ngx_listening_t)); if (cycle->listening.elts == NULL) { @@ -184,12 +225,23 @@ static ngx_cycle_t *ngx_init_cycle(ngx_c cycle->listening.nalloc = n; cycle->listening.pool = pool; + cycle->conf_ctx = ngx_pcalloc(pool, ngx_max_module * sizeof(void *)); if (cycle->conf_ctx == NULL) { ngx_destroy_pool(pool); return NULL; } + + ccf = ngx_pcalloc(pool, sizeof(ngx_core_conf_t)); + if (ccf == NULL) { + ngx_destroy_pool(pool); + return NULL; + } + ccf->daemon = -1; + ((void **)(cycle->conf_ctx))[ngx_core_module.index] = ccf; + + ngx_memzero(&conf, sizeof(ngx_conf_t)); /* STUB: init array ? */ conf.args = ngx_create_array(pool, 10, sizeof(ngx_str_t)); @@ -213,6 +265,7 @@ static ngx_cycle_t *ngx_init_cycle(ngx_c return NULL; } + failed = 0; file = cycle->open_files.elts; diff --git a/src/core/nginx.h b/src/core/nginx.h --- a/src/core/nginx.h +++ b/src/core/nginx.h @@ -9,5 +9,8 @@ extern int ngx_max_module; extern int ngx_connection_counter; +extern ngx_module_t ngx_core_module; + + #endif /* _NGINX_H_INCLUDED_ */ diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c --- a/src/core/ngx_conf_file.c +++ b/src/core/ngx_conf_file.c @@ -471,6 +471,13 @@ ngx_log_debug(cf->log, "FOUND %d:'%s'" _ } +char *ngx_conf_set_core_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, + void *conf) +{ + return ngx_conf_set_flag_slot(cf, cmd, *(void **)conf); +} + + char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { char *p = conf; diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h --- a/src/core/ngx_conf_file.h +++ b/src/core/ngx_conf_file.h @@ -184,6 +184,8 @@ char *ngx_conf_set_size_slot(ngx_conf_t char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); char *ngx_conf_set_time_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); +char *ngx_conf_set_core_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, + void *conf); extern ngx_module_t *ngx_modules[]; extern ngx_cycle_t *ngx_cycle; diff --git a/src/core/ngx_modules.c b/src/core/ngx_modules.c --- a/src/core/ngx_modules.c +++ b/src/core/ngx_modules.c @@ -3,6 +3,7 @@ #include +extern ngx_module_t ngx_core_module; extern ngx_module_t ngx_errlog_module; extern ngx_module_t ngx_events_module; @@ -46,6 +47,7 @@ ngx_module_t *ngx_modules[] = { /* core */ + &ngx_core_module, &ngx_errlog_module, /* events */ diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c --- a/src/event/ngx_event_accept.c +++ b/src/event/ngx_event_accept.c @@ -179,14 +179,12 @@ ngx_log_debug(ev->log, "ADDR %s" _ ls->l c->ctx = ls->ctx; c->servers = ls->servers; -#if 0 c->log = ngx_palloc(c->pool, sizeof(ngx_log_t)); if (c->log == NULL) { return; } ngx_memcpy(c->log, ev->log, sizeof(ngx_log_t)); -#endif - rev->log = wev->log = c->log = ev->log; + rev->log = wev->log = c->log; /* TODO: x86: MT: lock xadd, MP: lock xadd, shared */ c->number = ngx_connection_counter++; diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter.c --- a/src/http/modules/ngx_http_range_filter.c +++ b/src/http/modules/ngx_http_range_filter.c @@ -43,6 +43,7 @@ static int ngx_http_range_header_filter( int rc, boundary, len, i; char *p; off_t start, end; + ngx_table_elt_t *accept_ranges; ngx_http_range_t *range; ngx_http_range_filter_ctx_t *ctx; @@ -51,11 +52,24 @@ static int ngx_http_range_header_filter( || r->headers_out.status != NGX_HTTP_OK || r->headers_out.content_length == -1 /* STUB: we currently support ranges for file hunks only */ - || r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY - || r->headers_in.range == NULL + || r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY) + { + return next_header_filter(r); + } + + if (r->headers_in.range == NULL || r->headers_in.range->value.len < 7 || ngx_strncasecmp(r->headers_in.range->value.data, "bytes=", 6) != 0) { + ngx_test_null(accept_ranges, + ngx_push_table(r->headers_out.headers), + NGX_ERROR); + + accept_ranges->key.len = sizeof("Accept-Ranges") - 1; + accept_ranges->key.data = "Accept-Ranges"; + accept_ranges->value.len = sizeof("bytes") - 1; + accept_ranges->value.data = "bytes"; + return next_header_filter(r); }