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;
}
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;
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;
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;
}
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;
void *data;
ngx_shm_t shm;
ngx_shm_zone_init_pt init;
- ngx_str_t name;
void *tag;
};
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) {
}
ngx_sprintf(shpool->log_ctx, " in SSL session shared cache \"%V\"%Z",
- &shm_zone->name);
+ &shm_zone->shm.name);
shm_zone->data = cache;
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;
}
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;
}
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;
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;
}
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) {
}
ngx_sprintf(ctx->shpool->log_ctx, " in limit_req zone \"%V\"%Z",
- &shm_zone->name);
+ &shm_zone->shm.name);
return NGX_OK;
}
p = (u_char *) ngx_strchr(name.data, ':');
if (p) {
+ *p = '\0';
+
name.len = p - name.data;
p++;
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;
}
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;
}
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;
}
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;
}
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;
}
for (j = sizeof("shared:") - 1; j < value[i].len; j++) {
if (value[i].data[j] == ':') {
+ value[i].data[j] = '\0';
break;
}
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;
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) {
}
ngx_sprintf(cache->shpool->log_ctx, " in cache keys zone \"%V\"%Z",
- &shm_zone->name);
+ &shm_zone->shm.name);
return NGX_OK;
}
p = (u_char *) ngx_strchr(name.data, ':');
if (p) {
+ *p = '\0';
+
name.len = p - name.data;
p++;
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;
#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;
}
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;