# HG changeset patch # User Igor Sysoev # Date 1081526584 0 # Node ID 2e899477243a0ce3c4b59e699dbe9e86c42ebe38 # Parent 7a0dbd779c6d4f0d9f6afc292cf29919b1c61e69 nginx-0.0.3-2004-04-09-20:03:04 import diff --git a/auto/lib/pcre/conf b/auto/lib/pcre/conf --- a/auto/lib/pcre/conf +++ b/auto/lib/pcre/conf @@ -44,8 +44,8 @@ else ngx_lib_inc="#include " ngx_lib="PCRE library" - ngx_lib_test="pcre *re; pcre_compile(re, 0, NULL, 0, NULL)" - ngx_libs=-lpcre + ngx_lib_test="pcre *re; re = pcre_compile(NULL, 0, NULL, 0, NULL)" + ngx_libs="-lpcre" . auto/lib/test @@ -61,6 +61,7 @@ else ngx_lib="PCRE library in /usr/local/" ngx_lib_cflags="-I /usr/local/include" + ngx_libs="-L /usr/local/lib -lpcre" . auto/lib/test fi diff --git a/src/core/nginx.c b/src/core/nginx.c --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -65,7 +65,6 @@ ngx_module_t ngx_core_module = { ngx_int_t ngx_max_module; -ngx_atomic_t ngx_connection_counter; ngx_int_t ngx_process; ngx_pid_t ngx_pid; diff --git a/src/core/nginx.h b/src/core/nginx.h --- a/src/core/nginx.h +++ b/src/core/nginx.h @@ -12,9 +12,5 @@ extern ngx_module_t ngx_core_module; -extern ngx_atomic_t ngx_connection_counter; - -extern ngx_int_t ngx_process; - #endif /* _NGINX_H_INCLUDED_ */ diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h --- a/src/core/ngx_config.h +++ b/src/core/ngx_config.h @@ -83,6 +83,7 @@ typedef int ngx_flag_t; /* TODO: auto */ #define NGX_INT32_LEN sizeof("-2147483648") - 1 +#define NGX_INT64_LEN sizeof("-9223372036854775808") - 1 #define NGX_TIME_T_LEN sizeof("-2147483648") - 1 #define NGX_OFF_T_LEN sizeof("-9223372036854775808") - 1 diff --git a/src/event/modules/ngx_epoll_module.c b/src/event/modules/ngx_epoll_module.c --- a/src/event/modules/ngx_epoll_module.c +++ b/src/event/modules/ngx_epoll_module.c @@ -341,11 +341,12 @@ static int ngx_epoll_del_connection(ngx_ int ngx_epoll_process_events(ngx_cycle_t *cycle) { int events; + size_t n; ngx_int_t instance, i; ngx_uint_t lock, expire; - size_t n; + ngx_err_t err; + ngx_log_t *log; ngx_msec_t timer; - ngx_err_t err; struct timeval tv; ngx_connection_t *c; ngx_epoch_msec_t delta; @@ -416,6 +417,7 @@ int ngx_epoll_process_events(ngx_cycle_t } lock = 1; + log = cycle->log; for (i = 0; i < events; i++) { c = event_list[i].data.ptr; @@ -431,7 +433,11 @@ int ngx_epoll_process_events(ngx_cycle_t c->write->returned_instance = instance; } - ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0, +#if (NGX_DEBUG) + 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); @@ -442,19 +448,19 @@ int ngx_epoll_process_events(ngx_cycle_t * that was just closed in this iteration */ - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, "epoll: stale event " PTR_FMT, c); continue; } if (event_list[i].events & (EPOLLERR|EPOLLHUP)) { - ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, + ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0, "epoll_wait() error on fd:%d ev:%04X", c->fd, event_list[i].events); } if (event_list[i].events & ~(EPOLLIN|EPOLLOUT|EPOLLERR|EPOLLHUP)) { - ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, + ngx_log_error(NGX_LOG_ALERT, log, 0, "strange epoll_wait() events fd:%d ev:%04X", c->fd, event_list[i].events); } diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c --- a/src/event/ngx_event.c +++ b/src/event/ngx_event.c @@ -48,6 +48,10 @@ ngx_uint_t ngx_ev ngx_event_actions_t ngx_event_actions; +ngx_atomic_t connection_counter; +ngx_atomic_t *ngx_connection_counter = &connection_counter; + + ngx_atomic_t *ngx_accept_mutex_ptr; ngx_atomic_t *ngx_accept_mutex; ngx_uint_t ngx_accept_mutex_held; @@ -152,6 +156,9 @@ ngx_module_t ngx_event_core_module = { static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle) { #if !(WIN32) + + size_t size; + char *shared; ngx_core_conf_t *ccf; ngx_event_conf_t *ecf; @@ -163,19 +170,26 @@ static ngx_int_t ngx_event_module_init(n ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module); - if (ecf->accept_mutex == 0) { - return NGX_OK; - } + + /* TODO: 128 is cache line size */ - ngx_accept_mutex_ptr = (ngx_atomic_t *) mmap(NULL, sizeof(ngx_atomic_t), - PROT_READ|PROT_WRITE, - MAP_ANON|MAP_SHARED, -1, 0); + size = 128 /* ngx_accept_mutex */ + + 128; /* ngx_connection_counter */ - if (ngx_accept_mutex_ptr == NULL) { + shared = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0); + + if (shared == NULL) { ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, "mmap(MAP_ANON|MAP_SHARED) failed"); return NGX_ERROR; } + + if (ecf->accept_mutex) { + ngx_accept_mutex_ptr = (ngx_atomic_t *) shared; + } + + ngx_connection_counter = (ngx_atomic_t *) (shared + 128); + #endif return NGX_OK; diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h --- a/src/event/ngx_event.h +++ b/src/event/ngx_event.h @@ -407,6 +407,7 @@ typedef struct { } ngx_event_module_t; +extern ngx_atomic_t *ngx_connection_counter; extern ngx_atomic_t *ngx_accept_mutex_ptr; extern ngx_atomic_t *ngx_accept_mutex; 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 @@ -270,7 +270,7 @@ void ngx_event_accept(ngx_event_t *ev) * or protection by critical section or light mutex */ - c->number = ngx_atomic_inc(&ngx_connection_counter); + c->number = ngx_atomic_inc(ngx_connection_counter); ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, "accept: fd:%d c:%d", s, c->number); diff --git a/src/event/ngx_event_connect.c b/src/event/ngx_event_connect.c --- a/src/event/ngx_event_connect.c +++ b/src/event/ngx_event_connect.c @@ -202,7 +202,7 @@ int ngx_event_connect_peer(ngx_peer_conn * or protection by critical section or mutex */ - c->number = ngx_atomic_inc(&ngx_connection_counter); + c->number = ngx_atomic_inc(ngx_connection_counter); if (ngx_add_conn) { if (ngx_add_conn(c) == NGX_ERROR) { diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c --- a/src/os/unix/ngx_process_cycle.c +++ b/src/os/unix/ngx_process_cycle.c @@ -3,6 +3,8 @@ #include #include +#include + static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx); static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); @@ -531,3 +533,54 @@ int ngx_worker_thread_cycle(void *data) } #endif + + +static ngx_int_t ngx_create_pid_file(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) +{ + size_t len; + u_char pid[NGX_INT64_LEN + 1]; + ngx_core_conf_t *ccf; + + ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); + + if (ccf->pid.len == 0) { + ccf->pid.len = sizeof(NGINX_PID) - 1; + ccf->pid.data = NGINX_PID; + ccf->newpid.len = sizeof(NGINX_NEW_PID) - 1; + ccf->newpid.data = NGINX_NEW_PID; + + } else { + ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEW_PID_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_NEW_PID_EXT, sizeof(NGINX_NEW_PID_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); + 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; +}