aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2009-04-16 19:25:09 +0000
committerIgor Sysoev <igor@sysoev.ru>2009-04-16 19:25:09 +0000
commitc7f876bd4c3916b5a1553da88d73d97d76ac72e3 (patch)
tree1dfec08b372f51daed66162179b246e99217cabf
parentc26e7b9d49cf2d143b194342bf8d6f37de6ae197 (diff)
downloadnginx-c7f876bd4c3916b5a1553da88d73d97d76ac72e3.tar.gz
nginx-c7f876bd4c3916b5a1553da88d73d97d76ac72e3.zip
move zone name from ngx_shm_zone_t to ngx_shm_t to use Win32 shared memory
-rw-r--r--src/core/ngx_cycle.c37
-rw-r--r--src/core/ngx_cycle.h1
-rw-r--r--src/event/ngx_event_openssl.c4
-rw-r--r--src/http/modules/ngx_http_fastcgi_module.c2
-rw-r--r--src/http/modules/ngx_http_limit_req_module.c14
-rw-r--r--src/http/modules/ngx_http_limit_zone_module.c9
-rw-r--r--src/http/modules/ngx_http_proxy_module.c2
-rw-r--r--src/http/modules/ngx_http_ssl_module.c1
-rw-r--r--src/http/ngx_http_file_cache.c8
-rw-r--r--src/os/unix/ngx_shmem.h7
-rw-r--r--src/os/win32/ngx_shmem.c10
-rw-r--r--src/os/win32/ngx_shmem.h9
12 files changed, 55 insertions, 49 deletions
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
index 72b927a5c..42aa18b44 100644
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -412,7 +412,7 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
if (shm_zone[i].shm.size == 0) {
ngx_log_error(NGX_LOG_EMERG, log, 0,
"zero size shared memory zone \"%V\"",
- &shm_zone[i].name);
+ &shm_zone[i].shm.name);
goto failed;
}
@@ -437,12 +437,13 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
n = 0;
}
- if (shm_zone[i].name.len != oshm_zone[n].name.len) {
+ if (shm_zone[i].shm.name.len != oshm_zone[n].shm.name.len) {
continue;
}
- if (ngx_strncmp(shm_zone[i].name.data, oshm_zone[n].name.data,
- shm_zone[i].name.len)
+ if (ngx_strncmp(shm_zone[i].shm.name.data,
+ oshm_zone[n].shm.name.data,
+ shm_zone[i].shm.name.len)
!= 0)
{
continue;
@@ -672,10 +673,10 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
n = 0;
}
- if (oshm_zone[i].name.len == shm_zone[n].name.len
- && ngx_strncmp(oshm_zone[i].name.data,
- shm_zone[n].name.data,
- oshm_zone[i].name.len)
+ if (oshm_zone[i].shm.name.len == shm_zone[n].shm.name.len
+ && ngx_strncmp(oshm_zone[i].shm.name.data,
+ shm_zone[n].shm.name.data,
+ oshm_zone[i].shm.name.len)
== 0)
{
goto live_shm_zone;
@@ -1175,27 +1176,29 @@ ngx_shared_memory_add(ngx_conf_t *cf, ngx_str_t *name, size_t size, void *tag)
i = 0;
}
- if (name->len != shm_zone[i].name.len) {
+ if (name->len != shm_zone[i].shm.name.len) {
continue;
}
- if (ngx_strncmp(name->data, shm_zone[i].name.data, name->len) != 0) {
+ if (ngx_strncmp(name->data, shm_zone[i].shm.name.data, name->len)
+ != 0)
+ {
continue;
}
if (size && size != shm_zone[i].shm.size) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "the size %uz of shared memory zone \"%V\" "
- "conflicts with already declared size %uz",
- size, &shm_zone[i].name, shm_zone[i].shm.size);
+ "the size %uz of shared memory zone \"%V\" "
+ "conflicts with already declared size %uz",
+ size, &shm_zone[i].shm.name, shm_zone[i].shm.size);
return NULL;
}
if (tag != shm_zone[i].tag) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "the shared memory zone \"%V\" is "
- "already declared for a different use",
- &shm_zone[i].name);
+ "the shared memory zone \"%V\" is "
+ "already declared for a different use",
+ &shm_zone[i].shm.name);
return NULL;
}
@@ -1211,8 +1214,8 @@ ngx_shared_memory_add(ngx_conf_t *cf, ngx_str_t *name, size_t size, void *tag)
shm_zone->data = NULL;
shm_zone->shm.log = cf->cycle->log;
shm_zone->shm.size = size;
+ shm_zone->shm.name = *name;
shm_zone->init = NULL;
- shm_zone->name = *name;
shm_zone->tag = tag;
return shm_zone;
diff --git a/src/core/ngx_cycle.h b/src/core/ngx_cycle.h
index e42f46bb6..e7d611695 100644
--- a/src/core/ngx_cycle.h
+++ b/src/core/ngx_cycle.h
@@ -29,7 +29,6 @@ struct ngx_shm_zone_s {
void *data;
ngx_shm_t shm;
ngx_shm_zone_init_pt init;
- ngx_str_t name;
void *tag;
};
diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c
index ba3a035c4..2ab3f16fd 100644
--- a/src/event/ngx_event_openssl.c
+++ b/src/event/ngx_event_openssl.c
@@ -1433,7 +1433,7 @@ ngx_ssl_session_cache_init(ngx_shm_zone_t *shm_zone, void *data)
ngx_queue_init(&cache->expire_queue);
- len = sizeof(" in SSL session shared cache \"\"") + shm_zone->name.len;
+ len = sizeof(" in SSL session shared cache \"\"") + shm_zone->shm.name.len;
shpool->log_ctx = ngx_slab_alloc(shpool, len);
if (shpool->log_ctx == NULL) {
@@ -1441,7 +1441,7 @@ ngx_ssl_session_cache_init(ngx_shm_zone_t *shm_zone, void *data)
}
ngx_sprintf(shpool->log_ctx, " in SSL session shared cache \"%V\"%Z",
- &shm_zone->name);
+ &shm_zone->shm.name);
shm_zone->data = cache;
diff --git a/src/http/modules/ngx_http_fastcgi_module.c b/src/http/modules/ngx_http_fastcgi_module.c
index dfa5346f5..b0e959511 100644
--- a/src/http/modules/ngx_http_fastcgi_module.c
+++ b/src/http/modules/ngx_http_fastcgi_module.c
@@ -2043,7 +2043,7 @@ ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"\"fastcgi_cache\" zone \"%V\" is unknown",
- &shm_zone->name);
+ &shm_zone->shm.name);
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/ngx_http_limit_req_module.c b/src/http/modules/ngx_http_limit_req_module.c
index b3934076e..62bacaf0d 100644
--- a/src/http/modules/ngx_http_limit_req_module.c
+++ b/src/http/modules/ngx_http_limit_req_module.c
@@ -179,7 +179,7 @@ ngx_http_limit_req_handler(ngx_http_request_t *r)
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"limiting requests, excess: %ui.%03ui by zone \"%V\"",
- excess / 1000, excess % 1000, &lrcf->shm_zone->name);
+ excess / 1000, excess % 1000, &lrcf->shm_zone->shm.name);
return NGX_HTTP_SERVICE_UNAVAILABLE;
}
@@ -193,7 +193,7 @@ ngx_http_limit_req_handler(ngx_http_request_t *r)
ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
"delaying request, excess: %ui.%03ui, by zone \"%V\"",
- excess / 1000, excess % 1000, &lrcf->shm_zone->name);
+ excess / 1000, excess % 1000, &lrcf->shm_zone->shm.name);
if (ngx_handle_read_event(r->connection->read, 0) != NGX_OK) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
@@ -463,7 +463,7 @@ ngx_http_limit_req_init_zone(ngx_shm_zone_t *shm_zone, void *data)
ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0,
"limit_req \"%V\" uses the \"%V\" variable "
"while previously it used the \"%V\" variable",
- &shm_zone->name, &ctx->var, &octx->var);
+ &shm_zone->shm.name, &ctx->var, &octx->var);
return NGX_ERROR;
}
@@ -496,7 +496,7 @@ ngx_http_limit_req_init_zone(ngx_shm_zone_t *shm_zone, void *data)
ngx_queue_init(ctx->queue);
- len = sizeof(" in limit_req zone \"\"") + shm_zone->name.len;
+ len = sizeof(" in limit_req zone \"\"") + shm_zone->shm.name.len;
ctx->shpool->log_ctx = ngx_slab_alloc(ctx->shpool, len);
if (ctx->shpool->log_ctx == NULL) {
@@ -504,7 +504,7 @@ ngx_http_limit_req_init_zone(ngx_shm_zone_t *shm_zone, void *data)
}
ngx_sprintf(ctx->shpool->log_ctx, " in limit_req zone \"%V\"%Z",
- &shm_zone->name);
+ &shm_zone->shm.name);
return NGX_OK;
}
@@ -574,6 +574,8 @@ ngx_http_limit_req_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
p = (u_char *) ngx_strchr(name.data, ':');
if (p) {
+ *p = '\0';
+
name.len = p - name.data;
p++;
@@ -744,7 +746,7 @@ ngx_http_limit_req(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (lrcf->shm_zone->data == NULL) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"unknown limit_req_zone \"%V\"",
- &lrcf->shm_zone->name);
+ &lrcf->shm_zone->shm.name);
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/ngx_http_limit_zone_module.c b/src/http/modules/ngx_http_limit_zone_module.c
index 384155c85..b32c3da0e 100644
--- a/src/http/modules/ngx_http_limit_zone_module.c
+++ b/src/http/modules/ngx_http_limit_zone_module.c
@@ -191,7 +191,7 @@ ngx_http_limit_zone_handler(ngx_http_request_t *r)
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"limiting connections by zone \"%V\"",
- &lzcf->shm_zone->name);
+ &lzcf->shm_zone->shm.name);
return NGX_HTTP_SERVICE_UNAVAILABLE;
}
@@ -328,7 +328,7 @@ ngx_http_limit_zone_init_zone(ngx_shm_zone_t *shm_zone, void *data)
ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0,
"limit_zone \"%V\" uses the \"%V\" variable "
"while previously it used the \"%V\" variable",
- &shm_zone->name, &ctx->var, &octx->var);
+ &shm_zone->shm.name, &ctx->var, &octx->var);
return NGX_ERROR;
}
@@ -352,14 +352,15 @@ ngx_http_limit_zone_init_zone(ngx_shm_zone_t *shm_zone, void *data)
ngx_rbtree_init(ctx->rbtree, sentinel,
ngx_http_limit_zone_rbtree_insert_value);
- len = sizeof(" in limit_zone \"\"") + shm_zone->name.len;
+ len = sizeof(" in limit_zone \"\"") + shm_zone->shm.name.len;
shpool->log_ctx = ngx_slab_alloc(shpool, len);
if (shpool->log_ctx == NULL) {
return NGX_ERROR;
}
- ngx_sprintf(shpool->log_ctx, " in limit_zone \"%V\"%Z", &shm_zone->name);
+ ngx_sprintf(shpool->log_ctx, " in limit_zone \"%V\"%Z",
+ &shm_zone->shm.name);
return NGX_OK;
}
diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c
index 820e2d46c..60182d603 100644
--- a/src/http/modules/ngx_http_proxy_module.c
+++ b/src/http/modules/ngx_http_proxy_module.c
@@ -2104,7 +2104,7 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"\"proxy_cache\" zone \"%V\" is unknown",
- &shm_zone->name);
+ &shm_zone->shm.name);
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/ngx_http_ssl_module.c b/src/http/modules/ngx_http_ssl_module.c
index 91dad999e..3bf52a2c7 100644
--- a/src/http/modules/ngx_http_ssl_module.c
+++ b/src/http/modules/ngx_http_ssl_module.c
@@ -564,6 +564,7 @@ ngx_http_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
for (j = sizeof("shared:") - 1; j < value[i].len; j++) {
if (value[i].data[j] == ':') {
+ value[i].data[j] = '\0';
break;
}
diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c
index 145d61003..18794d8d0 100644
--- a/src/http/ngx_http_file_cache.c
+++ b/src/http/ngx_http_file_cache.c
@@ -54,7 +54,7 @@ ngx_http_file_cache_init(ngx_shm_zone_t *shm_zone, void *data)
ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0,
"cache \"%V\" uses the \"%V\" cache path "
"while previously it used the \"%V\" cache path",
- &shm_zone->name, &cache->path->name,
+ &shm_zone->shm.name, &cache->path->name,
&ocache->path->name);
return NGX_ERROR;
@@ -112,7 +112,7 @@ ngx_http_file_cache_init(ngx_shm_zone_t *shm_zone, void *data)
cache->max_size /= cache->bsize;
- len = sizeof(" in cache keys zone \"\"") + shm_zone->name.len;
+ len = sizeof(" in cache keys zone \"\"") + shm_zone->shm.name.len;
cache->shpool->log_ctx = ngx_slab_alloc(cache->shpool, len);
if (cache->shpool->log_ctx == NULL) {
@@ -120,7 +120,7 @@ ngx_http_file_cache_init(ngx_shm_zone_t *shm_zone, void *data)
}
ngx_sprintf(cache->shpool->log_ctx, " in cache keys zone \"%V\"%Z",
- &shm_zone->name);
+ &shm_zone->shm.name);
return NGX_OK;
}
@@ -1399,6 +1399,8 @@ ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
p = (u_char *) ngx_strchr(name.data, ':');
if (p) {
+ *p = '\0';
+
name.len = p - name.data;
p++;
diff --git a/src/os/unix/ngx_shmem.h b/src/os/unix/ngx_shmem.h
index 85ef019b7..d62680252 100644
--- a/src/os/unix/ngx_shmem.h
+++ b/src/os/unix/ngx_shmem.h
@@ -13,9 +13,10 @@
typedef struct {
- u_char *addr;
- size_t size;
- ngx_log_t *log;
+ u_char *addr;
+ size_t size;
+ ngx_str_t name;
+ ngx_log_t *log;
} ngx_shm_t;
diff --git a/src/os/win32/ngx_shmem.c b/src/os/win32/ngx_shmem.c
index 5c8fb6223..62e8585d0 100644
--- a/src/os/win32/ngx_shmem.c
+++ b/src/os/win32/ngx_shmem.c
@@ -8,20 +8,16 @@
#include <ngx_core.h>
-/*
- * TODO:
- * maping name or inheritable handle
- */
-
ngx_int_t
ngx_shm_alloc(ngx_shm_t *shm)
{
shm->handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
- 0, shm->size, NULL);
+ 0, shm->size, (char *) shm->name.data);
if (shm->handle == NULL) {
ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno,
- "CreateFileMapping(%uz) failed", shm->size);
+ "CreateFileMapping(%uz, %s) failed",
+ shm->size, shm->name.data);
return NGX_ERROR;
}
diff --git a/src/os/win32/ngx_shmem.h b/src/os/win32/ngx_shmem.h
index d1fe8f83f..7bd6d6265 100644
--- a/src/os/win32/ngx_shmem.h
+++ b/src/os/win32/ngx_shmem.h
@@ -13,10 +13,11 @@
typedef struct {
- u_char *addr;
- size_t size;
- HANDLE handle;
- ngx_log_t *log;
+ u_char *addr;
+ size_t size;
+ ngx_str_t name;
+ HANDLE handle;
+ ngx_log_t *log;
} ngx_shm_t;