Mercurial > hg > nginx
diff src/core/nginx.c @ 117:f6e3c5d019b6
nginx-0.0.1-2003-07-11-19:17:50 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 11 Jul 2003 15:17:50 +0000 |
parents | be27f922b9a2 |
children | 5bf52498665c |
line wrap: on
line diff
--- a/src/core/nginx.c Fri Jul 11 04:50:59 2003 +0000 +++ b/src/core/nginx.c Fri Jul 11 15:17:50 2003 +0000 @@ -9,10 +9,42 @@ 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 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 @@ #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 @@ 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 @@ 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 @@ 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 @@ 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 @@ return NULL; } + failed = 0; file = cycle->open_files.elts;