Klaus Demo nginx / f7a08d5
support attaching to an existent Win32 shared memory Igor Sysoev 13 years ago
13 changed file(s) with 228 addition(s) and 163 deletion(s). Raw diff Collapse all Expand all
88 #include <ngx_event.h>
99
1010
11 static ngx_int_t ngx_test_lockfile(u_char *file, ngx_log_t *log);
1211 static void ngx_destroy_cycle_pools(ngx_conf_t *conf);
1312 static ngx_int_t ngx_cmp_sockaddr(struct sockaddr *sa1, struct sockaddr *sa2);
13 static ngx_int_t ngx_init_zone_pool(ngx_cycle_t *cycle,
14 ngx_shm_zone_t *shm_zone);
15 static ngx_int_t ngx_test_lockfile(u_char *file, ngx_log_t *log);
1416 static void ngx_clean_old_cycles(ngx_event_t *ev);
1517
1618
4345 {
4446 void *rv;
4547 char **senv, **env;
46 u_char *lock_file;
4748 ngx_uint_t i, n;
4849 ngx_log_t *log;
4950 ngx_time_t *tp;
5152 ngx_pool_t *pool;
5253 ngx_cycle_t *cycle, **old;
5354 ngx_shm_zone_t *shm_zone, *oshm_zone;
54 ngx_slab_pool_t *shpool;
5555 ngx_list_part_t *part, *opart;
5656 ngx_open_file_t *file;
5757 ngx_listening_t *ls, *nls;
469469 goto failed;
470470 }
471471
472 shpool = (ngx_slab_pool_t *) shm_zone[i].shm.addr;
473
474 shpool->end = shm_zone[i].shm.addr + shm_zone[i].shm.size;
475 shpool->min_shift = 3;
476
477 #if (NGX_HAVE_ATOMIC_OPS)
478
479 lock_file = NULL;
480
481 #else
482
483 lock_file = ngx_pnalloc(cycle->pool,
484 cycle->lock_file.len + shm_zone[i].shm.name.len);
485
486 if (lock_file == NULL) {
487 goto failed;
488 }
489
490 (void) ngx_cpystrn(ngx_cpymem(lock_file, cycle->lock_file.data,
491 cycle->lock_file.len),
492 shm_zone[i].shm.name.data,
493 shm_zone[i].shm.name.len + 1);
494
495 #endif
496
497 if (ngx_shmtx_create(&shpool->mutex, (void *) &shpool->lock, lock_file)
498 != NGX_OK)
499 {
500 goto failed;
501 }
502
503 ngx_slab_init(shpool);
472 if (!shm_zone[i].shm.exists) {
473
474 if (ngx_init_zone_pool(cycle, &shm_zone[i]) != NGX_OK) {
475 goto failed;
476 }
477 }
504478
505479 if (shm_zone[i].init(&shm_zone[i], NULL) != NGX_OK) {
506480 goto failed;
918892 }
919893
920894
895 static ngx_int_t
896 ngx_init_zone_pool(ngx_cycle_t *cycle, ngx_shm_zone_t *zn)
897 {
898 u_char *file;
899 ngx_slab_pool_t *sp;
900
901 sp = (ngx_slab_pool_t *) zn->shm.addr;
902
903 sp->end = zn->shm.addr + zn->shm.size;
904 sp->min_shift = 3;
905
906 #if (NGX_HAVE_ATOMIC_OPS)
907
908 file = NULL;
909
910 #else
911
912 file = ngx_pnalloc(cycle->pool, cycle->lock_file.len + zn->shm.name.len);
913 if (file == NULL) {
914 return NGX_ERROR;
915 }
916
917 (void) ngx_sprintf(file, "%V%V%Z", &cycle->lock_file, &zn->shm.name);
918
919 #endif
920
921 if (ngx_shmtx_create(&sp->mutex, (void *) &sp->lock, file) != NGX_OK) {
922 return NGX_ERROR;
923 }
924
925 ngx_slab_init(sp);
926
927 return NGX_OK;
928 }
929
930
921931 #if !(NGX_WIN32)
922932
923933 ngx_int_t
12151225 shm_zone->shm.log = cf->cycle->log;
12161226 shm_zone->shm.size = size;
12171227 shm_zone->shm.name = *name;
1228 shm_zone->shm.exists = 0;
12181229 shm_zone->init = NULL;
12191230 shm_zone->tag = tag;
12201231
3636
3737 u_char *log_ctx;
3838 u_char zero;
39
40 void *data;
3941 } ngx_slab_pool_t;
4042
4143
505505 #endif
506506
507507 shm.size = size;
508 shm.name.len = sizeof("nginx_shared_zone");
509 shm.name.data = (u_char *) "nginx_shared_zone";
508510 shm.log = cycle->log;
509511
510512 if (ngx_shm_alloc(&shm) != NGX_OK) {
534536
535537 #endif
536538
537 *ngx_connection_counter = 1;
539 (void) ngx_atomic_cmp_set(ngx_connection_counter, 0, 1);
538540
539541 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
540542 "counter: %p, %d",
14201420 return NGX_OK;
14211421 }
14221422
1423 if (shm_zone->shm.exists) {
1424 shm_zone->data = data;
1425 return NGX_OK;
1426 }
1427
14231428 shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
14241429
14251430 cache = ngx_slab_alloc(shpool, sizeof(ngx_ssl_session_cache_t));
14271432 return NGX_ERROR;
14281433 }
14291434
1435 shpool->data = cache;
1436 shm_zone->data = cache;
1437
14301438 ngx_rbtree_init(&cache->session_rbtree, &cache->sentinel,
14311439 ngx_ssl_session_rbtree_insert_value);
14321440
14411449
14421450 ngx_sprintf(shpool->log_ctx, " in SSL session shared cache \"%V\"%Z",
14431451 &shm_zone->shm.name);
1444
1445 shm_zone->data = cache;
14461452
14471453 return NGX_OK;
14481454 }
99
1010
1111 typedef struct {
12 u_char color;
13 u_char dummy;
14 u_short len;
15 ngx_queue_t queue;
16 ngx_msec_t last;
17 ngx_uint_t excess; /* integer value, 1 corresponds to 0.001 r/s */
18 u_char data[1];
12 u_char color;
13 u_char dummy;
14 u_short len;
15 ngx_queue_t queue;
16 ngx_msec_t last;
17 /* integer value, 1 corresponds to 0.001 r/s */
18 ngx_uint_t excess;
19 u_char data[1];
1920 } ngx_http_limit_req_node_t;
2021
2122
2223 typedef struct {
23 ngx_rbtree_t *rbtree;
24 ngx_queue_t *queue;
25 ngx_slab_pool_t *shpool;
26 ngx_uint_t rate; /* integer value, 1 corresponds to 0.001 r/s */
27 ngx_int_t index;
28 ngx_str_t var;
24 ngx_rbtree_t rbtree;
25 ngx_rbtree_node_t sentinel;
26 ngx_queue_t queue;
27 } ngx_http_limit_req_shctx_t;
28
29
30 typedef struct {
31 ngx_http_limit_req_shctx_t *sh;
32 ngx_slab_pool_t *shpool;
33 /* integer value, 1 corresponds to 0.001 r/s */
34 ngx_uint_t rate;
35 ngx_int_t index;
36 ngx_str_t var;
2937 } ngx_http_limit_req_ctx_t;
3038
3139
3240 typedef struct {
33 ngx_shm_zone_t *shm_zone;
34 ngx_uint_t burst; /* integer value, 1 corresponds to 0.001 r/s */
35 ngx_uint_t nodelay;/* unsigned nodelay:1 */
41 ngx_shm_zone_t *shm_zone;
42 /* integer value, 1 corresponds to 0.001 r/s */
43 ngx_uint_t burst;
44 ngx_uint_t nodelay;/* unsigned nodelay:1 */
3645 } ngx_http_limit_req_conf_t;
3746
3847
162171 if (lr) {
163172 ngx_queue_remove(&lr->queue);
164173
165 ngx_queue_insert_head(ctx->queue, &lr->queue);
174 ngx_queue_insert_head(&ctx->sh->queue, &lr->queue);
166175
167176 excess = lr->excess;
168177
238247 lr->excess = 0;
239248 ngx_memcpy(lr->data, vv->data, len);
240249
241 ngx_rbtree_insert(ctx->rbtree, node);
242
243 ngx_queue_insert_head(ctx->queue, &lr->queue);
250 ngx_rbtree_insert(&ctx->sh->rbtree, node);
251
252 ngx_queue_insert_head(&ctx->sh->queue, &lr->queue);
244253
245254 done:
246255
323332
324333 ctx = lrcf->shm_zone->data;
325334
326 node = ctx->rbtree->root;
327 sentinel = ctx->rbtree->sentinel;
335 node = ctx->sh->rbtree.root;
336 sentinel = ctx->sh->rbtree.sentinel;
328337
329338 while (node != sentinel) {
330339
410419
411420 while (n < 3) {
412421
413 if (ngx_queue_empty(ctx->queue)) {
422 if (ngx_queue_empty(&ctx->sh->queue)) {
414423 return;
415424 }
416425
417 q = ngx_queue_last(ctx->queue);
426 q = ngx_queue_last(&ctx->sh->queue);
418427
419428 lr = ngx_queue_data(q, ngx_http_limit_req_node_t, queue);
420429
439448 node = (ngx_rbtree_node_t *)
440449 ((u_char *) lr - offsetof(ngx_rbtree_node_t, color));
441450
442 ngx_rbtree_delete(ctx->rbtree, node);
451 ngx_rbtree_delete(&ctx->sh->rbtree, node);
443452
444453 ngx_slab_free_locked(ctx->shpool, node);
445454 }
452461 ngx_http_limit_req_ctx_t *octx = data;
453462
454463 size_t len;
455 ngx_rbtree_node_t *sentinel;
456464 ngx_http_limit_req_ctx_t *ctx;
457465
458466 ctx = shm_zone->data;
466474 return NGX_ERROR;
467475 }
468476
469 ctx->rbtree = octx->rbtree;
470 ctx->queue = octx->queue;
477 ctx->sh = octx->sh;
471478 ctx->shpool = octx->shpool;
472479
473480 return NGX_OK;
475482
476483 ctx->shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
477484
478 ctx->rbtree = ngx_slab_alloc(ctx->shpool, sizeof(ngx_rbtree_t));
479 if (ctx->rbtree == NULL) {
485 if (shm_zone->shm.exists) {
486 ctx->sh = ctx->shpool->data;
487
488 return NGX_OK;
489 }
490
491 ctx->sh = ngx_slab_alloc(ctx->shpool, sizeof(ngx_http_limit_req_shctx_t));
492 if (ctx->sh == NULL) {
480493 return NGX_ERROR;
481494 }
482495
483 sentinel = ngx_slab_alloc(ctx->shpool, sizeof(ngx_rbtree_node_t));
484 if (sentinel == NULL) {
485 return NGX_ERROR;
486 }
487
488 ngx_rbtree_init(ctx->rbtree, sentinel,
496 ctx->shpool->data = ctx->sh;
497
498 ngx_rbtree_init(&ctx->sh->rbtree, &ctx->sh->sentinel,
489499 ngx_http_limit_req_rbtree_insert_value);
490500
491 ctx->queue = ngx_slab_alloc(ctx->shpool, sizeof(ngx_queue_t));
492 if (ctx->queue == NULL) {
493 return NGX_ERROR;
494 }
495
496 ngx_queue_init(ctx->queue);
501 ngx_queue_init(&ctx->sh->queue);
497502
498503 len = sizeof(" in limit_req zone \"\"") + shm_zone->shm.name.len;
499504
338338
339339 shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
340340
341 if (shm_zone->shm.exists) {
342 ctx->rbtree = shpool->data;
343
344 return NGX_OK;
345 }
346
341347 ctx->rbtree = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_t));
342348 if (ctx->rbtree == NULL) {
343349 return NGX_ERROR;
344350 }
351
352 shpool->data = ctx->rbtree;
345353
346354 sentinel = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_node_t));
347355 if (sentinel == NULL) {
9393 } ngx_http_file_cache_header_t;
9494
9595
96 typedef struct {
97 ngx_rbtree_t rbtree;
98 ngx_rbtree_node_t sentinel;
99 ngx_queue_t queue;
100 ngx_atomic_t cold;
101 off_t size;
102 } ngx_http_file_cache_sh_t;
103
104
96105 struct ngx_http_file_cache_s {
97 ngx_rbtree_t *rbtree;
98 ngx_queue_t *queue;
106 ngx_http_file_cache_sh_t *sh;
99107 ngx_slab_pool_t *shpool;
100108
101109 ngx_path_t *path;
102
103 ngx_atomic_t *cold;
104 off_t *size;
105110
106111 off_t max_size;
107112 size_t bsize;
4343 ngx_http_file_cache_t *ocache = data;
4444
4545 size_t len;
46 ngx_rbtree_node_t *sentinel;
4746 ngx_http_file_cache_t *cache;
4847
4948 cache = shm_zone->data;
5958 return NGX_ERROR;
6059 }
6160
62 cache->rbtree = ocache->rbtree;
63 cache->queue = ocache->queue;
61 cache->sh = ocache->sh;
62
6463 cache->shpool = ocache->shpool;
65 cache->cold = ocache->cold;
66 cache->size = ocache->size;
6764 cache->bsize = ocache->bsize;
6865
6966 cache->max_size /= cache->bsize;
7370
7471 cache->shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
7572
76 cache->rbtree = ngx_slab_alloc(cache->shpool, sizeof(ngx_rbtree_t));
77 if (cache->rbtree == NULL) {
73 if (shm_zone->shm.exists) {
74 cache->sh = cache->shpool->data;
75 cache->bsize = ngx_fs_bsize(cache->path->name.data);
76
77 return NGX_OK;
78 }
79
80 cache->sh = ngx_slab_alloc(cache->shpool, sizeof(ngx_http_file_cache_sh_t));
81 if (cache->sh == NULL) {
7882 return NGX_ERROR;
7983 }
8084
81 sentinel = ngx_slab_alloc(cache->shpool, sizeof(ngx_rbtree_node_t));
82 if (sentinel == NULL) {
83 return NGX_ERROR;
84 }
85
86 ngx_rbtree_init(cache->rbtree, sentinel,
85 cache->shpool->data = cache->sh;
86
87 ngx_rbtree_init(&cache->sh->rbtree, &cache->sh->sentinel,
8788 ngx_http_file_cache_rbtree_insert_value);
8889
89 cache->queue = ngx_slab_alloc(cache->shpool, sizeof(ngx_queue_t));
90 if (cache->queue == NULL) {
91 return NGX_ERROR;
92 }
93
94 ngx_queue_init(cache->queue);
95
96 cache->cold = ngx_slab_alloc(cache->shpool, sizeof(ngx_atomic_t));
97 if (cache->cold == NULL) {
98 return NGX_ERROR;
99 }
100
101 *cache->cold = 1;
102
103 cache->size = ngx_slab_alloc(cache->shpool, sizeof(off_t));
104 if (cache->size == NULL) {
105 return NGX_ERROR;
106 }
107
108 *cache->size = 0;
90 ngx_queue_init(&cache->sh->queue);
91
92 cache->sh->cold = 1;
93 cache->sh->size = 0;
10994
11095 cache->bsize = ngx_fs_bsize(cache->path->name.data);
11196
201186 return rc;
202187 }
203188
204 cold = *cache->cold;
189 cold = cache->sh->cold;
205190
206191 if (rc == NGX_OK) {
207192
336321 c->node->body_start = c->body_start;
337322 c->node->exists = 1;
338323
339 *cache->size += (c->length + cache->bsize - 1) / cache->bsize;
324 cache->sh->size += (c->length + cache->bsize - 1) / cache->bsize;
340325 }
341326
342327 ngx_shmtx_unlock(&cache->shpool->mutex);
433418 ngx_memcpy(fcn->key, &c->key[sizeof(ngx_rbtree_key_t)],
434419 NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t));
435420
436 ngx_rbtree_insert(cache->rbtree, &fcn->node);
421 ngx_rbtree_insert(&cache->sh->rbtree, &fcn->node);
437422
438423 renew:
439424
453438
454439 fcn->expire = ngx_time() + cache->inactive;
455440
456 ngx_queue_insert_head(cache->queue, &fcn->queue);
441 ngx_queue_insert_head(&cache->sh->queue, &fcn->queue);
457442
458443 c->uniq = fcn->uniq;
459444 c->uses = fcn->uses;
478463
479464 ngx_memcpy((u_char *) &node_key, key, sizeof(ngx_rbtree_key_t));
480465
481 node = cache->rbtree->root;
482 sentinel = cache->rbtree->sentinel;
466 node = cache->sh->rbtree.root;
467 sentinel = cache->sh->rbtree.sentinel;
483468
484469 while (node != sentinel) {
485470
662647
663648 c->node->length = c->length;
664649
665 *cache->size += size;
650 cache->sh->size += size;
666651
667652 if (rc == NGX_OK) {
668653 c->node->exists = 1;
827812
828813 ngx_shmtx_lock(&cache->shpool->mutex);
829814
830 for (q = ngx_queue_last(cache->queue);
831 q != ngx_queue_sentinel(cache->queue);
815 for (q = ngx_queue_last(&cache->sh->queue);
816 q != ngx_queue_sentinel(&cache->sh->queue);
832817 q = ngx_queue_prev(q))
833818 {
834819 fcn = ngx_queue_data(q, ngx_http_file_cache_node_t, queue);
852837 if (!fcn->exists) {
853838
854839 ngx_queue_remove(q);
855 ngx_rbtree_delete(cache->rbtree, &fcn->node);
840 ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node);
856841 ngx_slab_free_locked(cache->shpool, fcn);
857842
858843 break;
901886
902887 for ( ;; ) {
903888
904 if (ngx_queue_empty(cache->queue)) {
889 if (ngx_queue_empty(&cache->sh->queue)) {
905890 wait = 10;
906891 break;
907892 }
908893
909 q = ngx_queue_last(cache->queue);
894 q = ngx_queue_last(&cache->sh->queue);
910895
911896 fcn = ngx_queue_data(q, ngx_http_file_cache_node_t, queue);
912897
938923 */
939924
940925 ngx_queue_remove(q);
941 ngx_rbtree_delete(cache->rbtree, &fcn->node);
926 ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node);
942927
943928 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
944929 "ignore long locked inactive cache entry %*s, count:%d",
950935 if (!fcn->exists) {
951936
952937 ngx_queue_remove(q);
953 ngx_rbtree_delete(cache->rbtree, &fcn->node);
938 ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node);
954939 ngx_slab_free_locked(cache->shpool, fcn);
955940
956941 continue;
978963
979964 fcn = ngx_queue_data(q, ngx_http_file_cache_node_t, queue);
980965
981 *cache->size -= (fcn->length + cache->bsize - 1) / cache->bsize;
966 cache->sh->size -= (fcn->length + cache->bsize - 1) / cache->bsize;
982967
983968 path = cache->path;
984969
992977
993978 ngx_queue_remove(q);
994979
995 ngx_rbtree_delete(cache->rbtree, &fcn->node);
980 ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node);
996981
997982 ngx_slab_free_locked(cache->shpool, fcn);
998983
10231008 time_t next;
10241009 ngx_tree_ctx_t tree;
10251010
1026 if (*cache->cold) {
1011 if (cache->sh->cold) {
10271012
10281013 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
10291014 "http file cache manager update");
10441029 return 10;
10451030 }
10461031
1047 *cache->cold = 0;
1032 cache->sh->cold = 0;
10481033
10491034 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0,
10501035 "http file cache: %V %.3fM, bsize: %uz",
10511036 &cache->path->name,
1052 ((double) *cache->size * cache->bsize) / (1024 * 1024),
1037 ((double) cache->sh->size * cache->bsize) / (1024 * 1024),
10531038 cache->bsize);
10541039 }
10551040
10611046 for ( ;; ) {
10621047 ngx_shmtx_lock(&cache->shpool->mutex);
10631048
1064 size = *cache->size;
1049 size = cache->sh->size;
10651050
10661051 ngx_shmtx_unlock(&cache->shpool->mutex);
10671052
12441229 ngx_memcpy(fcn->key, &c->key[sizeof(ngx_rbtree_key_t)],
12451230 NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t));
12461231
1247 ngx_rbtree_insert(cache->rbtree, &fcn->node);
1232 ngx_rbtree_insert(&cache->sh->rbtree, &fcn->node);
12481233
12491234 fcn->uses = 1;
12501235 fcn->count = 0;
12561241 fcn->body_start = c->body_start;
12571242 fcn->length = c->length;
12581243
1259 *cache->size += (c->length + cache->bsize - 1) / cache->bsize;
1244 cache->sh->size += (c->length + cache->bsize - 1) / cache->bsize;
12601245
12611246 } else {
12621247 ngx_queue_remove(&fcn->queue);
12641249
12651250 fcn->expire = ngx_time() + cache->inactive;
12661251
1267 ngx_queue_insert_head(cache->queue, &fcn->queue);
1252 ngx_queue_insert_head(&cache->sh->queue, &fcn->queue);
12681253
12691254 ngx_shmtx_unlock(&cache->shpool->mutex);
12701255
1212
1313
1414 typedef struct {
15 u_char *addr;
16 size_t size;
17 ngx_str_t name;
18 ngx_log_t *log;
15 u_char *addr;
16 size_t size;
17 ngx_str_t name;
18 ngx_log_t *log;
19 ngx_uint_t exists; /* unsigned exists:1; */
1920 } ngx_shm_t;
2021
2122
5353 extern ngx_uint_t ngx_tcp_nodelay_and_tcp_nopush;
5454 extern ngx_uint_t ngx_win32_version;
5555 extern ngx_fd_t ngx_stderr_fileno;
56 extern char ngx_unique[];
5657
5758
5859
1010 ngx_int_t
1111 ngx_shm_alloc(ngx_shm_t *shm)
1212 {
13 u_char *name;
14
15 name = ngx_alloc(shm->name.len + 2 + sizeof(NGX_INT32_LEN), shm->log);
16 if (name == NULL) {
17 return NGX_ERROR;
18 }
19
20 ngx_sprintf(name, "%V_%s%Z", &shm->name, ngx_unique);
21
22 ngx_set_errno(0);
23
1324 shm->handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
14 0, shm->size, (char *) shm->name.data);
25 0, shm->size, (char *) name);
1526
1627 if (shm->handle == NULL) {
1728 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno,
1829 "CreateFileMapping(%uz, %s) failed",
1930 shm->size, shm->name.data);
20 return NGX_ERROR;
31 goto failed;
32 }
33
34 if (ngx_errno == ERROR_ALREADY_EXISTS) {
35 shm->exists = 1;
2136 }
2237
2338 shm->addr = MapViewOfFile(shm->handle, FILE_MAP_WRITE, 0, 0, 0);
2439
25 if (shm->addr == NULL) {
26 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno,
27 "MapViewOfFile(%uz) failed", shm->size);
28
29 if (CloseHandle(shm->handle) == 0) {
30 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno,
31 "CloseHandle() failed");
32 }
33
34 return NGX_ERROR;
40 if (shm->addr != NULL) {
41 return NGX_OK;
3542 }
3643
37 return NGX_OK;
44 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno,
45 "MapViewOfFile(%uz) failed", shm->size);
46
47 if (CloseHandle(shm->handle) == 0) {
48 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno,
49 "CloseHandle() failed");
50 }
51
52 failed:
53
54 ngx_free(name);
55
56 return NGX_ERROR;
3857 }
3958
4059
1212
1313
1414 typedef struct {
15 u_char *addr;
16 size_t size;
17 ngx_str_t name;
18 HANDLE handle;
19 ngx_log_t *log;
15 u_char *addr;
16 size_t size;
17 ngx_str_t name;
18 HANDLE handle;
19 ngx_log_t *log;
20 ngx_uint_t exists; /* unsigned exists:1; */
2021 } ngx_shm_t;
2122
2223
1616 ngx_uint_t ngx_tcp_nodelay_and_tcp_nopush;
1717
1818 ngx_fd_t ngx_stderr_fileno;
19 char ngx_unique[NGX_INT32_LEN + 1];
1920
2021
2122 ngx_os_io_t ngx_os_io = {
5960 DWORD bytes;
6061 SOCKET s;
6162 WSADATA wsd;
63 ngx_err_t err;
6264 ngx_uint_t n;
6365 SYSTEM_INFO si;
6466
204206 ngx_close_socket_n " failed");
205207 }
206208
209 if (GetEnvironmentVariable("nginx_unique", ngx_unique, NGX_INT32_LEN + 1)
210 != 0)
211 {
212 ngx_process = NGX_PROCESS_WORKER;
213
214 } else {
215 err = ngx_errno;
216
217 if (err != ERROR_ENVVAR_NOT_FOUND) {
218 ngx_log_error(NGX_LOG_EMERG, log, err,
219 "GetEnvironmentVariable(\"nginx_unique\") failed");
220 return NGX_ERROR;
221 }
222
223 ngx_sprintf((u_char *) ngx_unique, "%P%Z", ngx_pid);
224 }
225
207226 return NGX_OK;
208227 }
209228