Mercurial > hg > nginx
changeset 311:11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 12 Apr 2004 16:38:09 +0000 |
parents | a9a9af2c7370 |
children | f5431a4bbc7d |
files | auto/lib/zlib/make src/core/nginx.c src/core/ngx_conf_file.c src/core/ngx_conf_file.h src/core/ngx_cycle.c src/core/ngx_cycle.h src/core/ngx_log.c src/event/modules/ngx_epoll_module.c src/event/modules/ngx_kqueue_module.c src/event/ngx_event.c src/http/ngx_http.c src/http/ngx_http_config.h src/os/unix/ngx_process_cycle.c src/os/unix/ngx_process_cycle.h |
diffstat | 14 files changed, 274 insertions(+), 330 deletions(-) [+] |
line wrap: on
line diff
--- a/auto/lib/zlib/make Mon Apr 12 06:10:53 2004 +0000 +++ b/auto/lib/zlib/make Mon Apr 12 16:38:09 2004 +0000 @@ -76,6 +76,14 @@ done=YES ;; + + *) + echo "$0: error: invalid --with-zlib=asm=$ZLIB_ASM option." + echo "The valid values are \"pentium\" and \"pentiumpro\" only". + echo + + exit 1; + ;; esac ;;
--- a/src/core/nginx.c Mon Apr 12 06:10:53 2004 +0000 +++ b/src/core/nginx.c Mon Apr 12 16:38:09 2004 +0000 @@ -7,45 +7,44 @@ static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle); static ngx_int_t ngx_getopt(ngx_master_ctx_t *ctx, ngx_cycle_t *cycle); -static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle); +static void *ngx_core_module_create_conf(ngx_cycle_t *cycle); +static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf); static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); -static ngx_str_t core_name = ngx_string("core"); - static ngx_command_t ngx_core_commands[] = { + { ngx_string("daemon"), + NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1, + ngx_conf_set_flag_slot, + 0, + offsetof(ngx_core_conf_t, daemon), + NULL }, + + { ngx_string("master_process"), + NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1, + ngx_conf_set_flag_slot, + 0, + offsetof(ngx_core_conf_t, master), + NULL }, + + { ngx_string("worker_processes"), + NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1, + ngx_conf_set_num_slot, + 0, + offsetof(ngx_core_conf_t, worker_processes), + NULL }, + { ngx_string("user"), - NGX_MAIN_CONF|NGX_CONF_TAKE12, + NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE12, ngx_set_user, 0, 0, NULL }, - { ngx_string("daemon"), - NGX_MAIN_CONF|NGX_CONF_TAKE1, - ngx_conf_set_core_flag_slot, - 0, - offsetof(ngx_core_conf_t, daemon), - NULL }, - - { ngx_string("master_process"), - NGX_MAIN_CONF|NGX_CONF_TAKE1, - ngx_conf_set_core_flag_slot, - 0, - offsetof(ngx_core_conf_t, master), - NULL }, - - { ngx_string("worker_processes"), - NGX_MAIN_CONF|NGX_CONF_TAKE1, - ngx_conf_set_core_num_slot, - 0, - offsetof(ngx_core_conf_t, worker_processes), - NULL }, - { ngx_string("pid"), - NGX_MAIN_CONF|NGX_CONF_TAKE1, - ngx_conf_set_core_str_slot, + NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1, + ngx_conf_set_str_slot, 0, offsetof(ngx_core_conf_t, pid), NULL }, @@ -54,22 +53,29 @@ }; +static ngx_core_module_t ngx_core_module_ctx = { + ngx_string("core"), + ngx_core_module_create_conf, + ngx_core_module_init_conf +}; + + ngx_module_t ngx_core_module = { NGX_MODULE, - &core_name, /* module context */ + &ngx_core_module_ctx, /* module context */ ngx_core_commands, /* module directives */ NGX_CORE_MODULE, /* module type */ - ngx_core_module_init, /* init module */ + NULL, /* init module */ NULL /* init child */ }; -ngx_int_t ngx_max_module; +ngx_int_t ngx_max_module; -ngx_int_t ngx_process; -ngx_pid_t ngx_pid; -ngx_pid_t ngx_new_binary; -ngx_int_t ngx_inherited; +ngx_int_t ngx_process; +ngx_pid_t ngx_pid; +ngx_pid_t ngx_new_binary; +ngx_int_t ngx_inherited; int main(int argc, char *const *argv) @@ -149,69 +155,32 @@ ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); - ngx_process = (ccf->master != 0) ? NGX_PROCESS_MASTER : NGX_PROCESS_SINGLE; + ngx_process = ccf->master ? NGX_PROCESS_MASTER : NGX_PROCESS_SINGLE; #if (WIN32) #if 0 - - if (run_as_service) { - if (ngx_servie(cycle->log) == NGX_ERROR) { + if (ccf->run_as_service) { + if (ngx_service(cycle->log) == NGX_ERROR) { return 1; } return 0; } - #endif #else - if (!ngx_inherited && ccf->daemon != 0) { + if (!ngx_inherited && ccf->daemon) { if (ngx_daemon(cycle->log) == NGX_ERROR) { return 1; } } - if (ccf->pid.len == 0) { - ccf->pid.len = sizeof(NGINX_PID) - 1; - ccf->pid.data = NGINX_PID; - ccf->newpid.len = sizeof(NGINX_NEWPID) - 1; - ccf->newpid.data = NGINX_NEWPID; - - } else { - ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEWPID_EXT); - if (!(ccf->newpid.data = ngx_alloc(ccf->newpid.len, cycle->log))) { - return 1; - } - - ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len), - NGINX_NEWPID_EXT, sizeof(NGINX_NEWPID_EXT)); - } - - len = ngx_snprintf((char *) pid, /* STUB */ 10, PID_T_FMT, ngx_getpid()); - ngx_memzero(&ctx.pid, sizeof(ngx_file_t)); - ctx.pid.name = ngx_inherited ? ccf->newpid : ccf->pid; - ctx.name = ccf->pid.data; - - ctx.pid.fd = ngx_open_file(ctx.pid.name.data, NGX_FILE_RDWR, - NGX_FILE_CREATE_OR_OPEN); - - if (ctx.pid.fd == NGX_INVALID_FILE) { - ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, - ngx_open_file_n " \"%s\" failed", ctx.pid.name.data); + if (ngx_create_pidfile(cycle, NULL) == NGX_ERROR) { return 1; } - if (ngx_write_file(&ctx.pid, pid, len, 0) == NGX_ERROR) { - return 1; - } - - if (ngx_close_file(ctx.pid.fd) == NGX_FILE_ERROR) { - ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, - ngx_close_file_n " \"%s\" failed", ctx.pid.name.data); - } - #endif ngx_master_process_cycle(cycle, &ctx); @@ -336,22 +305,12 @@ } -static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle) +static void *ngx_core_module_create_conf(ngx_cycle_t *cycle) { ngx_core_conf_t *ccf; - /* - * ngx_core_module has a special init procedure: it is called by - * ngx_init_cycle() before the configuration file parsing to create - * ngx_core_module configuration and to set its default parameters - */ - - if (((void **)(cycle->conf_ctx))[ngx_core_module.index] != NULL) { - return NGX_OK; - } - if (!(ccf = ngx_pcalloc(cycle->pool, sizeof(ngx_core_conf_t)))) { - return NGX_ERROR; + return NULL; } /* set by pcalloc() * @@ -364,9 +323,41 @@ ccf->user = (ngx_uid_t) NGX_CONF_UNSET; ccf->group = (ngx_gid_t) NGX_CONF_UNSET; - ((void **)(cycle->conf_ctx))[ngx_core_module.index] = ccf; + return ccf; +} + + +static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf) +{ + ngx_core_conf_t *ccf = conf; + + ngx_conf_init_value(ccf->daemon, 1); + ngx_conf_init_value(ccf->master, 1); + ngx_conf_init_value(ccf->worker_processes, 1); + +#if !(WIN32) + + /* TODO: default "nobody" user */ - return NGX_OK; + if (ccf->pid.len == 0) { + ccf->pid.len = sizeof(NGINX_PID) - 1; + ccf->pid.data = NGINX_PID; + ccf->newpid.len = sizeof(NGINX_NEWPID) - 1; + ccf->newpid.data = NGINX_NEWPID; + + } else { + ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEWPID_EXT); + + if (!(ccf->newpid.data = ngx_palloc(cycle->pool, ccf->newpid.len))) { + return NGX_CONF_ERROR; + } + + ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len), + NGINX_NEWPID_EXT, sizeof(NGINX_NEWPID_EXT)); + } +#endif + + return NGX_CONF_OK; } @@ -381,12 +372,11 @@ #else + ngx_core_conf_t *ccf = conf; + struct passwd *pwd; struct group *grp; ngx_str_t *value; - ngx_core_conf_t *ccf; - - ccf = *(void **)conf; if (ccf->user != (uid_t) NGX_CONF_UNSET) { return "is duplicate";
--- a/src/core/ngx_conf_file.c Mon Apr 12 06:10:53 2004 +0000 +++ b/src/core/ngx_conf_file.c Mon Apr 12 16:38:09 2004 +0000 @@ -13,9 +13,7 @@ NGX_CONF_TAKE4, NGX_CONF_TAKE5, NGX_CONF_TAKE6, - NGX_CONF_TAKE7, - NGX_CONF_TAKE8, - NGX_CONF_TAKE9, + NGX_CONF_TAKE7 }; static int ngx_conf_read_token(ngx_conf_t *cf); @@ -204,7 +202,10 @@ conf = NULL; - if (cf->module_type == NGX_CORE_MODULE) { + if (cmd->type & NGX_DIRECT_CONF) { + conf = ((void **) cf->ctx)[ngx_modules[m]->index]; + + } else if (cmd->type & NGX_MAIN_CONF) { conf = &(((void **) cf->ctx)[ngx_modules[m]->index]); } else if (cf->ctx) { @@ -564,27 +565,6 @@ } -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_core_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) -{ - return ngx_conf_set_num_slot(cf, cmd, *(void **)conf); -} - - -char *ngx_conf_set_core_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) -{ - return ngx_conf_set_str_slot(cf, cmd, *(void **)conf); -} - - char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { char *p = conf;
--- a/src/core/ngx_conf_file.h Mon Apr 12 06:10:53 2004 +0000 +++ b/src/core/ngx_conf_file.h Mon Apr 12 16:38:09 2004 +0000 @@ -20,8 +20,6 @@ #define NGX_CONF_TAKE5 0x00000020 #define NGX_CONF_TAKE6 0x00000040 #define NGX_CONF_TAKE7 0x00000080 -#define NGX_CONF_TAKE8 0x00000100 -#define NGX_CONF_TAKE9 0x00000200 #define NGX_CONF_TAKE12 (NGX_CONF_TAKE1|NGX_CONF_TAKE2) #define NGX_CONF_TAKE13 (NGX_CONF_TAKE1|NGX_CONF_TAKE3) @@ -31,13 +29,14 @@ #define NGX_CONF_TAKE1234 (NGX_CONF_TAKE1|NGX_CONF_TAKE2|NGX_CONF_TAKE3 \ |NGX_CONF_TAKE4) -#define NGX_CONF_ARGS_NUMBER 0x0000ffff -#define NGX_CONF_BLOCK 0x00010000 -#define NGX_CONF_FLAG 0x00020000 -#define NGX_CONF_ANY 0x00040000 -#define NGX_CONF_1MORE 0x00080000 -#define NGX_CONF_2MORE 0x00100000 +#define NGX_CONF_ARGS_NUMBER 0x000000ff +#define NGX_CONF_BLOCK 0x00000100 +#define NGX_CONF_FLAG 0x00000200 +#define NGX_CONF_ANY 0x00000400 +#define NGX_CONF_1MORE 0x00000800 +#define NGX_CONF_2MORE 0x00001000 +#define NGX_DIRECT_CONF 0x00010000 #define NGX_MAIN_CONF 0x01000000 @@ -102,6 +101,13 @@ typedef struct { + ngx_str_t name; + void *(*create_conf)(ngx_cycle_t *cycle); + char *(*init_conf)(ngx_cycle_t *cycle, void *conf); +} ngx_core_module_t; + + +typedef struct { ngx_file_t file; ngx_hunk_t *hunk; int line; @@ -254,13 +260,6 @@ char *ngx_conf_set_bufs_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); char *ngx_conf_set_bitmask_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); -char *ngx_conf_set_core_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); -char *ngx_conf_set_core_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); - extern ngx_int_t ngx_max_module; extern ngx_module_t *ngx_modules[];
--- a/src/core/ngx_cycle.c Mon Apr 12 06:10:53 2004 +0000 +++ b/src/core/ngx_cycle.c Mon Apr 12 16:38:09 2004 +0000 @@ -2,8 +2,6 @@ #include <ngx_config.h> #include <ngx_core.h> #include <ngx_event.h> -/* STUB */ -#include <nginx.h> static void ngx_clean_old_cycles(ngx_event_t *ev); @@ -23,15 +21,16 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) { - ngx_uint_t i, n, failed; - ngx_log_t *log; - ngx_conf_t conf; - ngx_pool_t *pool; - ngx_cycle_t *cycle, **old; - ngx_socket_t fd; - ngx_open_file_t *file; - ngx_core_conf_t *ccf; - ngx_listening_t *ls, *nls; + void *rv; + ngx_uint_t i, n, failed; + ngx_log_t *log; + ngx_conf_t conf; + ngx_pool_t *pool; + ngx_cycle_t *cycle, **old; + ngx_socket_t fd; + ngx_open_file_t *file; + ngx_listening_t *ls, *nls; + ngx_core_module_t *module; log = old_cycle->log; @@ -97,9 +96,21 @@ } - if (ngx_core_module.init_module(cycle) == NGX_ERROR) { - ngx_destroy_pool(pool); - return NULL; + for (i = 0; ngx_modules[i]; i++) { + if (ngx_modules[i]->type != NGX_CORE_MODULE) { + continue; + } + + module = ngx_modules[i]->ctx; + + if (module->create_conf) { + rv = module->create_conf(cycle); + if (rv == NGX_CONF_ERROR) { + ngx_destroy_pool(pool); + return NULL; + } + cycle->conf_ctx[ngx_modules[i]->index] = rv; + } } @@ -125,47 +136,74 @@ } - failed = 0; - - - - file = cycle->open_files.elts; - for (i = 0; i < cycle->open_files.nelts; i++) { - if (file[i].name.data == NULL) { + for (i = 0; ngx_modules[i]; i++) { + if (ngx_modules[i]->type != NGX_CORE_MODULE) { continue; } - file[i].fd = ngx_open_file(file[i].name.data, - NGX_FILE_RDWR, - NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); + module = ngx_modules[i]->ctx; + + if (module->init_conf) { + if (module->init_conf(cycle, cycle->conf_ctx[ngx_modules[i]->index]) + == NGX_CONF_ERROR) + { + ngx_destroy_pool(pool); + return NULL; + } + } + } + + + failed = 0; + - if (file[i].fd == NGX_INVALID_FILE) { - ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, - ngx_open_file_n " \"%s\" failed", - file[i].name.data); - failed = 1; - break; - } +#if !(WIN32) + if (ngx_create_pidfile(cycle, old_cycle) == NGX_ERROR) { + failed = 1; + } +#endif + + + if (!failed) { + file = cycle->open_files.elts; + for (i = 0; i < cycle->open_files.nelts; i++) { + if (file[i].name.data == NULL) { + continue; + } + + file[i].fd = ngx_open_file(file[i].name.data, + NGX_FILE_RDWR, + NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); + + if (file[i].fd == NGX_INVALID_FILE) { + ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, + ngx_open_file_n " \"%s\" failed", + file[i].name.data); + failed = 1; + break; + } #if (WIN32) - if (ngx_file_append_mode(file[i].fd) == NGX_ERROR) { - ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, - ngx_file_append_mode_n " \"%s\" failed", - file[i].name.data); - failed = 1; - break; - } + if (ngx_file_append_mode(file[i].fd) == NGX_ERROR) { + ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, + ngx_file_append_mode_n " \"%s\" failed", + file[i].name.data); + failed = 1; + break; + } #else - if (fcntl(file[i].fd, F_SETFD, FD_CLOEXEC) == -1) { - ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, - "fcntl(FD_CLOEXEC) \"%s\" failed", - file[i].name.data); - failed = 1; - break; + if (fcntl(file[i].fd, F_SETFD, FD_CLOEXEC) == -1) { + ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, + "fcntl(FD_CLOEXEC) \"%s\" failed", + file[i].name.data); + failed = 1; + break; + } +#endif } -#endif } + if (!failed) { if (old_cycle->listening.nelts) { ls = old_cycle->listening.elts; @@ -374,75 +412,77 @@ } -static ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle) +#if !(WIN32) + +ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle) { - size_t len; - u_char pid[NGX_INT64_LEN + 1]; - ngx_str_t name; - ngx_core_conf_t *ccf; + size_t len; + u_char *name, pid[NGX_INT64_LEN + 1]; + ngx_file_t file; + ngx_core_conf_t *ccf, *old_ccf; + + if (old_cycle && old_cycle->conf_ctx == NULL) { + + /* + * do not create the pid file in the first ngx_init_cycle() call + * because we need to write the demonized process pid + */ + + return NGX_OK; + } ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); - if (ctx->pid.len) { - if (ccf->pid.len == 0) { - return NGX_OK; - } + if (old_cycle) { + old_ccf = (ngx_core_conf_t *) ngx_get_conf(old_cycle->conf_ctx, + ngx_core_module); - if (ctx->pid.len == ccf->pid.len - && ngx_strcmp(ctx->pid.data, ccf->pid.data) == 0) + if (ccf->pid.len == old_ccf->pid.len + && ngx_strcmp(ccf->pid.data, old_ccf->pid.data) == 0) { return NGX_OK; } } - - if (ccf->pid.len == 0) { - ccf->pid.len = sizeof(NGINX_PID) - 1; - ccf->pid.data = NGINX_PID; - ccf->newpid.len = sizeof(NGINX_NEWPID) - 1; - ccf->newpid.data = NGINX_NEWPID; - - } else { - ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEWPID_EXT); - if (!(ccf->newpid.data = ngx_alloc(ccf->newpid.len, cycle->log))) { - return NGX_ERROR; - } - - ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len), - NGINX_NEWPID_EXT, sizeof(NGINX_NEWPID_EXT)); - } len = ngx_snprintf((char *) pid, NGX_INT64_LEN + 1, PID_T_FMT, ngx_pid); - ngx_memzero(&ctx->pid, sizeof(ngx_file_t)); - ctx->pid.name = ngx_inherited ? ccf->newpid : ccf->pid; - ctx->name = ccf->pid.data; + + ngx_memzero(&file, sizeof(ngx_file_t)); + file.name = (ngx_inherited && getppid() > 1) ? ccf->newpid : ccf->pid; + file.log = cycle->log; - ctx->pid.fd = ngx_open_file(ctx->pid.name.data, NGX_FILE_RDWR, - NGX_FILE_CREATE_OR_OPEN); + file.fd = ngx_open_file(file.name.data, NGX_FILE_RDWR, + NGX_FILE_CREATE_OR_OPEN); - if (ctx->pid.fd == NGX_INVALID_FILE) { + if (file.fd == NGX_INVALID_FILE) { ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, - ngx_open_file_n " \"%s\" failed", ctx->pid.name.data); + ngx_open_file_n " \"%s\" failed", file.name.data); return NGX_ERROR; } - if (ngx_write_file(&ctx->pid, pid, len, 0) == NGX_ERROR) { + if (ngx_write_file(&file, pid, len, 0) == NGX_ERROR) { return NGX_ERROR; } - if (ngx_close_file(ctx->pid.fd) == NGX_FILE_ERROR) { + if (ngx_close_file(file.fd) == NGX_FILE_ERROR) { ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, - ngx_close_file_n " \"%s\" failed", ctx->pid.name.data); + ngx_close_file_n " \"%s\" failed", file.name.data); } + ngx_delete_pidfile(old_cycle); + return NGX_OK; } -static void ngx_delete_pidfile(ngx_cycle_t *cycle) +void ngx_delete_pidfile(ngx_cycle_t *cycle) { u_char *name; ngx_core_conf_t *ccf; + if (cycle == NULL || cycle->conf_ctx == NULL) { + return; + } + ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); if (ngx_inherited && getppid() > 1) { @@ -458,6 +498,8 @@ } } +#endif + void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user) {
--- a/src/core/ngx_cycle.h Mon Apr 12 06:10:53 2004 +0000 +++ b/src/core/ngx_cycle.h Mon Apr 12 16:38:09 2004 +0000 @@ -40,6 +40,8 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle); +ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle); +void ngx_delete_pidfile(ngx_cycle_t *cycle); void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user); ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv);
--- a/src/core/ngx_log.c Mon Apr 12 06:10:53 2004 +0000 +++ b/src/core/ngx_log.c Mon Apr 12 16:38:09 2004 +0000 @@ -7,8 +7,6 @@ static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); -static ngx_str_t errlog_name = ngx_string("errlog"); - static ngx_command_t ngx_errlog_commands[] = { {ngx_string("error_log"), @@ -22,9 +20,16 @@ }; +static ngx_core_module_t ngx_errlog_module_ctx = { + ngx_string("errlog"), + NULL, + NULL +}; + + ngx_module_t ngx_errlog_module = { NGX_MODULE, - &errlog_name, /* module context */ + &ngx_errlog_module_ctx, /* module context */ ngx_errlog_commands, /* module directives */ NGX_CORE_MODULE, /* module type */ NULL, /* init module */
--- a/src/event/modules/ngx_epoll_module.c Mon Apr 12 06:10:53 2004 +0000 +++ b/src/event/modules/ngx_epoll_module.c Mon Apr 12 16:38:09 2004 +0000 @@ -263,6 +263,7 @@ if (flags & NGX_CLOSE_EVENT) { ev->active = 0; + ev->posted = 0; return NGX_OK; } @@ -437,10 +438,6 @@ log = c->log ? c->log : cycle->log; #endif - ngx_log_debug3(NGX_LOG_DEBUG_EVENT, log, 0, - "epoll: fd:%d ev:%04X d:" PTR_FMT, - c->fd, event_list[i].events, event_list[i].data); - if (c->read->instance != instance) { /* @@ -453,6 +450,10 @@ continue; } + ngx_log_debug3(NGX_LOG_DEBUG_EVENT, log, 0, + "epoll: fd:%d ev:%04X d:" PTR_FMT, + c->fd, event_list[i].events, event_list[i].data); + if (event_list[i].events & (EPOLLERR|EPOLLHUP)) { ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0, "epoll_wait() error on fd:%d ev:%04X",
--- a/src/event/modules/ngx_kqueue_module.c Mon Apr 12 06:10:53 2004 +0000 +++ b/src/event/modules/ngx_kqueue_module.c Mon Apr 12 16:38:09 2004 +0000 @@ -263,6 +263,7 @@ */ if (flags & NGX_CLOSE_EVENT) { + ev->posted = 0; return NGX_OK; } @@ -464,10 +465,6 @@ ev = (ngx_event_t *) ((uintptr_t) ev & (uintptr_t) ~1); ev->returned_instance = instance; - if (ev->log && (ev->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { - ngx_kqueue_dump_event(ev->log, &event_list[i]); - } - if (!ev->active || ev->instance != instance) { /* @@ -480,6 +477,10 @@ continue; } + if (ev->log && (ev->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { + ngx_kqueue_dump_event(ev->log, &event_list[i]); + } + ev->available = event_list[i].data; if (event_list[i].flags & EV_EOF) {
--- a/src/event/ngx_event.c Mon Apr 12 06:10:53 2004 +0000 +++ b/src/event/ngx_event.c Mon Apr 12 16:38:09 2004 +0000 @@ -59,8 +59,6 @@ -static ngx_str_t events_name = ngx_string("events"); - static ngx_command_t ngx_events_commands[] = { { ngx_string("events"), @@ -73,10 +71,17 @@ ngx_null_command }; + +static ngx_core_module_t ngx_events_module_ctx = { + ngx_string("events"), + NULL, + NULL +}; + ngx_module_t ngx_events_module = { NGX_MODULE, - &events_name, /* module context */ + &ngx_events_module_ctx, /* module context */ ngx_events_commands, /* module directives */ NGX_CORE_MODULE, /* module type */ NULL, /* init module */
--- a/src/http/ngx_http.c Mon Apr 12 06:10:53 2004 +0000 +++ b/src/http/ngx_http.c Mon Apr 12 16:38:09 2004 +0000 @@ -18,9 +18,6 @@ int (*ngx_http_top_body_filter) (ngx_http_request_t *r, ngx_chain_t *ch); -static ngx_str_t http_name = ngx_string("http"); - - static ngx_command_t ngx_http_commands[] = { {ngx_string("http"), @@ -33,10 +30,17 @@ ngx_null_command }; + +static ngx_core_module_t ngx_http_module_ctx = { + ngx_string("http"), + NULL, + NULL +}; + ngx_module_t ngx_http_module = { NGX_MODULE, - &http_name, /* module context */ + &ngx_http_module_ctx, /* module context */ ngx_http_commands, /* module directives */ NGX_CORE_MODULE, /* module type */ NULL, /* init module */
--- a/src/http/ngx_http_config.h Mon Apr 12 06:10:53 2004 +0000 +++ b/src/http/ngx_http_config.h Mon Apr 12 16:38:09 2004 +0000 @@ -35,9 +35,9 @@ #define NGX_HTTP_MODULE 0x50545448 /* "HTTP" */ -#define NGX_HTTP_MAIN_CONF 0x2000000 -#define NGX_HTTP_SRV_CONF 0x4000000 -#define NGX_HTTP_LOC_CONF 0x8000000 +#define NGX_HTTP_MAIN_CONF 0x02000000 +#define NGX_HTTP_SRV_CONF 0x04000000 +#define NGX_HTTP_LOC_CONF 0x08000000 #define NGX_HTTP_MAIN_CONF_OFFSET offsetof(ngx_http_conf_ctx_t, main_conf)
--- a/src/os/unix/ngx_process_cycle.c Mon Apr 12 06:10:53 2004 +0000 +++ b/src/os/unix/ngx_process_cycle.c Mon Apr 12 16:38:09 2004 +0000 @@ -12,8 +12,6 @@ static int ngx_worker_thread_cycle(void *data); #endif -static void ngx_delete_pidfile(ngx_cycle_t *cycle); - ngx_int_t ngx_process; ngx_pid_t ngx_pid; @@ -76,10 +74,6 @@ ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); - if (ccf->worker_processes == NGX_CONF_UNSET) { - ccf->worker_processes = 1; - } - if (ngx_process == NGX_PROCESS_MASTER) { for (i = 0; i < (ngx_uint_t) ccf->worker_processes; i++) { ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL, @@ -524,88 +518,3 @@ } #endif - - -static ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) -{ - size_t len; - u_char pid[NGX_INT64_LEN + 1]; - ngx_str_t name; - ngx_core_conf_t *ccf; - - ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); - - if (ctx->pid.len) { - if (ccf->pid.len == 0) { - return NGX_OK; - } - - if (ctx->pid.len == ccf->pid.len - && ngx_strcmp(ctx->pid.data, ccf->pid.data) == 0) - { - return NGX_OK; - } - } - - if (ccf->pid.len == 0) { - ccf->pid.len = sizeof(NGINX_PID) - 1; - ccf->pid.data = NGINX_PID; - ccf->newpid.len = sizeof(NGINX_NEWPID) - 1; - ccf->newpid.data = NGINX_NEWPID; - - } else { - ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEWPID_EXT); - if (!(ccf->newpid.data = ngx_alloc(ccf->newpid.len, cycle->log))) { - return NGX_ERROR; - } - - ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len), - NGINX_NEWPID_EXT, sizeof(NGINX_NEWPID_EXT)); - } - - len = ngx_snprintf((char *) pid, NGX_INT64_LEN + 1, PID_T_FMT, ngx_pid); - ngx_memzero(&ctx->pid, sizeof(ngx_file_t)); - ctx->pid.name = ngx_inherited ? ccf->newpid : ccf->pid; - ctx->name = ccf->pid.data; - - ctx->pid.fd = ngx_open_file(ctx->pid.name.data, NGX_FILE_RDWR, - NGX_FILE_CREATE_OR_OPEN); - - if (ctx->pid.fd == NGX_INVALID_FILE) { - ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, - ngx_open_file_n " \"%s\" failed", ctx->pid.name.data); - return NGX_ERROR; - } - - if (ngx_write_file(&ctx->pid, pid, len, 0) == NGX_ERROR) { - return NGX_ERROR; - } - - if (ngx_close_file(ctx->pid.fd) == NGX_FILE_ERROR) { - ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, - ngx_close_file_n " \"%s\" failed", ctx->pid.name.data); - } - - return NGX_OK; -} - - -static void ngx_delete_pidfile(ngx_cycle_t *cycle) -{ - u_char *name; - ngx_core_conf_t *ccf; - - ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); - - if (ngx_inherited && getppid() > 1) { - name = ccf->newpid.data; - - } else { - name = ccf->pid.data; - } - - if (ngx_delete_file(name) == NGX_FILE_ERROR) { - ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, - ngx_delete_file_n " \"%s\" failed", name); - } -}