Skip to content

Commit c7f876b

Browse files
committed
move zone name from ngx_shm_zone_t to ngx_shm_t to use Win32 shared memory
1 parent c26e7b9 commit c7f876b

12 files changed

+55
-49
lines changed

src/core/ngx_cycle.c

+20-17
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
412412
if (shm_zone[i].shm.size == 0) {
413413
ngx_log_error(NGX_LOG_EMERG, log, 0,
414414
"zero size shared memory zone \"%V\"",
415-
&shm_zone[i].name);
415+
&shm_zone[i].shm.name);
416416
goto failed;
417417
}
418418

@@ -437,12 +437,13 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
437437
n = 0;
438438
}
439439

440-
if (shm_zone[i].name.len != oshm_zone[n].name.len) {
440+
if (shm_zone[i].shm.name.len != oshm_zone[n].shm.name.len) {
441441
continue;
442442
}
443443

444-
if (ngx_strncmp(shm_zone[i].name.data, oshm_zone[n].name.data,
445-
shm_zone[i].name.len)
444+
if (ngx_strncmp(shm_zone[i].shm.name.data,
445+
oshm_zone[n].shm.name.data,
446+
shm_zone[i].shm.name.len)
446447
!= 0)
447448
{
448449
continue;
@@ -672,10 +673,10 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
672673
n = 0;
673674
}
674675

675-
if (oshm_zone[i].name.len == shm_zone[n].name.len
676-
&& ngx_strncmp(oshm_zone[i].name.data,
677-
shm_zone[n].name.data,
678-
oshm_zone[i].name.len)
676+
if (oshm_zone[i].shm.name.len == shm_zone[n].shm.name.len
677+
&& ngx_strncmp(oshm_zone[i].shm.name.data,
678+
shm_zone[n].shm.name.data,
679+
oshm_zone[i].shm.name.len)
679680
== 0)
680681
{
681682
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)
11751176
i = 0;
11761177
}
11771178

1178-
if (name->len != shm_zone[i].name.len) {
1179+
if (name->len != shm_zone[i].shm.name.len) {
11791180
continue;
11801181
}
11811182

1182-
if (ngx_strncmp(name->data, shm_zone[i].name.data, name->len) != 0) {
1183+
if (ngx_strncmp(name->data, shm_zone[i].shm.name.data, name->len)
1184+
!= 0)
1185+
{
11831186
continue;
11841187
}
11851188

11861189
if (size && size != shm_zone[i].shm.size) {
11871190
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1188-
"the size %uz of shared memory zone \"%V\" "
1189-
"conflicts with already declared size %uz",
1190-
size, &shm_zone[i].name, shm_zone[i].shm.size);
1191+
"the size %uz of shared memory zone \"%V\" "
1192+
"conflicts with already declared size %uz",
1193+
size, &shm_zone[i].shm.name, shm_zone[i].shm.size);
11911194
return NULL;
11921195
}
11931196

11941197
if (tag != shm_zone[i].tag) {
11951198
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1196-
"the shared memory zone \"%V\" is "
1197-
"already declared for a different use",
1198-
&shm_zone[i].name);
1199+
"the shared memory zone \"%V\" is "
1200+
"already declared for a different use",
1201+
&shm_zone[i].shm.name);
11991202
return NULL;
12001203
}
12011204

@@ -1211,8 +1214,8 @@ ngx_shared_memory_add(ngx_conf_t *cf, ngx_str_t *name, size_t size, void *tag)
12111214
shm_zone->data = NULL;
12121215
shm_zone->shm.log = cf->cycle->log;
12131216
shm_zone->shm.size = size;
1217+
shm_zone->shm.name = *name;
12141218
shm_zone->init = NULL;
1215-
shm_zone->name = *name;
12161219
shm_zone->tag = tag;
12171220

12181221
return shm_zone;

src/core/ngx_cycle.h

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ struct ngx_shm_zone_s {
2929
void *data;
3030
ngx_shm_t shm;
3131
ngx_shm_zone_init_pt init;
32-
ngx_str_t name;
3332
void *tag;
3433
};
3534

src/event/ngx_event_openssl.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1433,15 +1433,15 @@ ngx_ssl_session_cache_init(ngx_shm_zone_t *shm_zone, void *data)
14331433

14341434
ngx_queue_init(&cache->expire_queue);
14351435

1436-
len = sizeof(" in SSL session shared cache \"\"") + shm_zone->name.len;
1436+
len = sizeof(" in SSL session shared cache \"\"") + shm_zone->shm.name.len;
14371437

14381438
shpool->log_ctx = ngx_slab_alloc(shpool, len);
14391439
if (shpool->log_ctx == NULL) {
14401440
return NGX_ERROR;
14411441
}
14421442

14431443
ngx_sprintf(shpool->log_ctx, " in SSL session shared cache \"%V\"%Z",
1444-
&shm_zone->name);
1444+
&shm_zone->shm.name);
14451445

14461446
shm_zone->data = cache;
14471447

src/http/modules/ngx_http_fastcgi_module.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2043,7 +2043,7 @@ ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
20432043

20442044
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
20452045
"\"fastcgi_cache\" zone \"%V\" is unknown",
2046-
&shm_zone->name);
2046+
&shm_zone->shm.name);
20472047

20482048
return NGX_CONF_ERROR;
20492049
}

src/http/modules/ngx_http_limit_req_module.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ ngx_http_limit_req_handler(ngx_http_request_t *r)
179179

180180
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
181181
"limiting requests, excess: %ui.%03ui by zone \"%V\"",
182-
excess / 1000, excess % 1000, &lrcf->shm_zone->name);
182+
excess / 1000, excess % 1000, &lrcf->shm_zone->shm.name);
183183

184184
return NGX_HTTP_SERVICE_UNAVAILABLE;
185185
}
@@ -193,7 +193,7 @@ ngx_http_limit_req_handler(ngx_http_request_t *r)
193193

194194
ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
195195
"delaying request, excess: %ui.%03ui, by zone \"%V\"",
196-
excess / 1000, excess % 1000, &lrcf->shm_zone->name);
196+
excess / 1000, excess % 1000, &lrcf->shm_zone->shm.name);
197197

198198
if (ngx_handle_read_event(r->connection->read, 0) != NGX_OK) {
199199
return NGX_HTTP_INTERNAL_SERVER_ERROR;
@@ -463,7 +463,7 @@ ngx_http_limit_req_init_zone(ngx_shm_zone_t *shm_zone, void *data)
463463
ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0,
464464
"limit_req \"%V\" uses the \"%V\" variable "
465465
"while previously it used the \"%V\" variable",
466-
&shm_zone->name, &ctx->var, &octx->var);
466+
&shm_zone->shm.name, &ctx->var, &octx->var);
467467
return NGX_ERROR;
468468
}
469469

@@ -496,15 +496,15 @@ ngx_http_limit_req_init_zone(ngx_shm_zone_t *shm_zone, void *data)
496496

497497
ngx_queue_init(ctx->queue);
498498

499-
len = sizeof(" in limit_req zone \"\"") + shm_zone->name.len;
499+
len = sizeof(" in limit_req zone \"\"") + shm_zone->shm.name.len;
500500

501501
ctx->shpool->log_ctx = ngx_slab_alloc(ctx->shpool, len);
502502
if (ctx->shpool->log_ctx == NULL) {
503503
return NGX_ERROR;
504504
}
505505

506506
ngx_sprintf(ctx->shpool->log_ctx, " in limit_req zone \"%V\"%Z",
507-
&shm_zone->name);
507+
&shm_zone->shm.name);
508508

509509
return NGX_OK;
510510
}
@@ -574,6 +574,8 @@ ngx_http_limit_req_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
574574
p = (u_char *) ngx_strchr(name.data, ':');
575575

576576
if (p) {
577+
*p = '\0';
578+
577579
name.len = p - name.data;
578580

579581
p++;
@@ -744,7 +746,7 @@ ngx_http_limit_req(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
744746
if (lrcf->shm_zone->data == NULL) {
745747
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
746748
"unknown limit_req_zone \"%V\"",
747-
&lrcf->shm_zone->name);
749+
&lrcf->shm_zone->shm.name);
748750
return NGX_CONF_ERROR;
749751
}
750752

src/http/modules/ngx_http_limit_zone_module.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ ngx_http_limit_zone_handler(ngx_http_request_t *r)
191191

192192
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
193193
"limiting connections by zone \"%V\"",
194-
&lzcf->shm_zone->name);
194+
&lzcf->shm_zone->shm.name);
195195

196196
return NGX_HTTP_SERVICE_UNAVAILABLE;
197197
}
@@ -328,7 +328,7 @@ ngx_http_limit_zone_init_zone(ngx_shm_zone_t *shm_zone, void *data)
328328
ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0,
329329
"limit_zone \"%V\" uses the \"%V\" variable "
330330
"while previously it used the \"%V\" variable",
331-
&shm_zone->name, &ctx->var, &octx->var);
331+
&shm_zone->shm.name, &ctx->var, &octx->var);
332332
return NGX_ERROR;
333333
}
334334

@@ -352,14 +352,15 @@ ngx_http_limit_zone_init_zone(ngx_shm_zone_t *shm_zone, void *data)
352352
ngx_rbtree_init(ctx->rbtree, sentinel,
353353
ngx_http_limit_zone_rbtree_insert_value);
354354

355-
len = sizeof(" in limit_zone \"\"") + shm_zone->name.len;
355+
len = sizeof(" in limit_zone \"\"") + shm_zone->shm.name.len;
356356

357357
shpool->log_ctx = ngx_slab_alloc(shpool, len);
358358
if (shpool->log_ctx == NULL) {
359359
return NGX_ERROR;
360360
}
361361

362-
ngx_sprintf(shpool->log_ctx, " in limit_zone \"%V\"%Z", &shm_zone->name);
362+
ngx_sprintf(shpool->log_ctx, " in limit_zone \"%V\"%Z",
363+
&shm_zone->shm.name);
363364

364365
return NGX_OK;
365366
}

src/http/modules/ngx_http_proxy_module.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,7 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
21042104

21052105
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
21062106
"\"proxy_cache\" zone \"%V\" is unknown",
2107-
&shm_zone->name);
2107+
&shm_zone->shm.name);
21082108

21092109
return NGX_CONF_ERROR;
21102110
}

src/http/modules/ngx_http_ssl_module.c

+1
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ ngx_http_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
564564

565565
for (j = sizeof("shared:") - 1; j < value[i].len; j++) {
566566
if (value[i].data[j] == ':') {
567+
value[i].data[j] = '\0';
567568
break;
568569
}
569570

src/http/ngx_http_file_cache.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ ngx_http_file_cache_init(ngx_shm_zone_t *shm_zone, void *data)
5454
ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0,
5555
"cache \"%V\" uses the \"%V\" cache path "
5656
"while previously it used the \"%V\" cache path",
57-
&shm_zone->name, &cache->path->name,
57+
&shm_zone->shm.name, &cache->path->name,
5858
&ocache->path->name);
5959

6060
return NGX_ERROR;
@@ -112,15 +112,15 @@ ngx_http_file_cache_init(ngx_shm_zone_t *shm_zone, void *data)
112112

113113
cache->max_size /= cache->bsize;
114114

115-
len = sizeof(" in cache keys zone \"\"") + shm_zone->name.len;
115+
len = sizeof(" in cache keys zone \"\"") + shm_zone->shm.name.len;
116116

117117
cache->shpool->log_ctx = ngx_slab_alloc(cache->shpool, len);
118118
if (cache->shpool->log_ctx == NULL) {
119119
return NGX_ERROR;
120120
}
121121

122122
ngx_sprintf(cache->shpool->log_ctx, " in cache keys zone \"%V\"%Z",
123-
&shm_zone->name);
123+
&shm_zone->shm.name);
124124

125125
return NGX_OK;
126126
}
@@ -1399,6 +1399,8 @@ ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
13991399
p = (u_char *) ngx_strchr(name.data, ':');
14001400

14011401
if (p) {
1402+
*p = '\0';
1403+
14021404
name.len = p - name.data;
14031405

14041406
p++;

src/os/unix/ngx_shmem.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313

1414

1515
typedef struct {
16-
u_char *addr;
17-
size_t size;
18-
ngx_log_t *log;
16+
u_char *addr;
17+
size_t size;
18+
ngx_str_t name;
19+
ngx_log_t *log;
1920
} ngx_shm_t;
2021

2122

src/os/win32/ngx_shmem.c

+3-7
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,16 @@
88
#include <ngx_core.h>
99

1010

11-
/*
12-
* TODO:
13-
* maping name or inheritable handle
14-
*/
15-
1611
ngx_int_t
1712
ngx_shm_alloc(ngx_shm_t *shm)
1813
{
1914
shm->handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
20-
0, shm->size, NULL);
15+
0, shm->size, (char *) shm->name.data);
2116

2217
if (shm->handle == NULL) {
2318
ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno,
24-
"CreateFileMapping(%uz) failed", shm->size);
19+
"CreateFileMapping(%uz, %s) failed",
20+
shm->size, shm->name.data);
2521
return NGX_ERROR;
2622
}
2723

src/os/win32/ngx_shmem.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313

1414

1515
typedef struct {
16-
u_char *addr;
17-
size_t size;
18-
HANDLE handle;
19-
ngx_log_t *log;
16+
u_char *addr;
17+
size_t size;
18+
ngx_str_t name;
19+
HANDLE handle;
20+
ngx_log_t *log;
2021
} ngx_shm_t;
2122

2223

0 commit comments

Comments
 (0)