diff src/core/ngx_cycle.c @ 258:6ae1357b7b7c NGINX_0_4_14

nginx 0.4.14 *) Feature: the "proxy_pass_error_message" directive in IMAP/POP3 proxy. *) Feature: now configure detects system PCRE library on FreeBSD, Linux, and NetBSD. *) Bugfix: ngx_http_perl_module did not work with perl built with the threads support; bug appeared in 0.3.38. *) Bugfix: ngx_http_perl_module did not work if perl was called recursively. *) Bugfix: nginx ignored a host name in an request line. *) Bugfix: a worker process may got caught in an endless loop, if a FastCGI server sent too many data to the stderr. *) Bugfix: the $upstream_response_time variable may be negative if the system time was changed backward. *) Bugfix: the "Auth-Login-Attempt" parameter was not sent to IMAP/POP3 proxy authentication server when POP3 was used. *) Bugfix: a segmentation fault might occur if connect to IMAP/POP3 proxy authentication server failed.
author Igor Sysoev <http://sysoev.ru>
date Mon, 27 Nov 2006 00:00:00 +0300
parents 73e8476f9142
children 6eb1e38f0f1f
line wrap: on
line diff
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -43,12 +43,15 @@ ngx_cycle_t *
 ngx_init_cycle(ngx_cycle_t *old_cycle)
 {
     void               *rv;
+    u_char             *lock_file;
     ngx_uint_t          i, n;
     ngx_log_t          *log;
     ngx_conf_t          conf;
     ngx_pool_t         *pool;
     ngx_cycle_t        *cycle, **old;
-    ngx_list_part_t    *part;
+    ngx_shm_zone_t     *shm, *oshm;
+    ngx_slab_pool_t    *shpool;
+    ngx_list_part_t    *part, *opart;
     ngx_open_file_t    *file;
     ngx_listening_t    *ls, *nls;
     ngx_core_conf_t    *ccf;
@@ -120,6 +123,25 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
     }
 
 
+    if (old_cycle->shared_memory.part.nelts) {
+        n = old_cycle->shared_memory.part.nelts;
+        for (part = old_cycle->shared_memory.part.next; part; part = part->next)
+        {
+            n += part->nelts;
+        }
+
+    } else {
+        n = 1;
+    }
+
+    if (ngx_list_init(&cycle->shared_memory, pool, n, sizeof(ngx_shm_zone_t))
+        == NGX_ERROR)
+    {
+        ngx_destroy_pool(pool);
+        return NULL;
+    }
+
+
     cycle->new_log = ngx_log_create_errlog(cycle, NULL);
     if (cycle->new_log == NULL) {
         ngx_destroy_pool(pool);
@@ -183,21 +205,6 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
     }
 
 
-#if 0
-    cycle->shm.size = /* STUB */ ngx_pagesize;
-    cycle->shm.log = log;
-
-    if (ngx_shm_alloc(&cycle->shm) != NGX_OK) {
-        ngx_destroy_pool(conf.temp_pool);
-        ngx_destroy_pool(pool);
-        return NULL;
-    }
-
-    cycle->shm_last = cycle->shm.addr;
-    cycle->shm_end = cycle->shm.addr + cycle->shm.size;
-#endif
-
-
     conf.ctx = cycle->conf_ctx;
     conf.cycle = cycle;
     conf.pool = pool;
@@ -274,7 +281,7 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
 #endif
 
 
-    if (ngx_test_lockfile(ccf->lock_file.data, log) != NGX_OK) {
+    if (ngx_test_lockfile(cycle->lock_file.data, log) != NGX_OK) {
         goto failed;
     }
 
@@ -343,6 +350,94 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
     }
 
 
+    /* create shared memory */
+
+    part = &cycle->shared_memory.part;
+    shm = part->elts;
+
+    for (i = 0; /* void */ ; i++) {
+
+        if (i >= part->nelts) {
+            if (part->next == NULL) {
+                break;
+            }
+            part = part->next;
+            shm = part->elts;
+            i = 0;
+        }
+
+        shm[i].shm.log = cycle->log;
+
+        opart = &old_cycle->shared_memory.part;
+        oshm = opart->elts;
+
+        for (n = 0; /* void */ ; n++) {
+
+            if (n >= opart->nelts) {
+                if (opart->next == NULL) {
+                    break;
+                }
+                opart = opart->next;
+                oshm = opart->elts;
+                n = 0;
+            }
+
+            if (ngx_strcmp(shm[i].name.data, oshm[n].name.data) != 0) {
+                continue;
+            }
+
+            if (shm[i].shm.size == oshm[n].shm.size) {
+                shm[i].shm.addr = oshm[n].shm.addr;
+                goto found;
+            }
+
+            ngx_shm_free(&oshm[n].shm);
+
+            break;
+        }
+
+        if (ngx_shm_alloc(&shm[i].shm) != NGX_OK) {
+            goto failed;
+        }
+
+        shpool = (ngx_slab_pool_t *) shm[i].shm.addr;
+
+        shpool->end = shm[i].shm.addr + shm[i].shm.size;
+        shpool->min_shift = 3;
+
+#if (NGX_HAVE_ATOMIC_OPS)
+
+        lock_file = NULL;
+
+#else
+
+        lock_file = ngx_palloc(cycle->pool,
+                               cycle->lock_file.len + shm[i].name.len);
+
+        if (lock_file == NULL) {
+            goto failed;
+        }
+
+        (void) ngx_cpystrn(ngx_cpymem(lock_file, cycle->lock_file.data,
+                                      cycle->lock_file.len),
+                           shm[i].name.data, shm[i].name.len + 1);
+
+#endif
+
+        if (ngx_shmtx_create(&shpool->mutex, (void *) &shpool->lock, lock_file)
+            != NGX_OK)
+        {
+            goto failed;
+        }
+
+        ngx_slab_init(shpool);
+
+    found:
+
+        continue;
+    }
+
+
     /* handle the listening sockets */
 
     if (old_cycle->listening.nelts) {
@@ -521,12 +616,7 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
 
     if (ngx_process == NGX_PROCESS_MASTER || ngx_is_init_cycle(old_cycle)) {
 
-        if (old_cycle->shm.addr) {
-            ngx_shm_free(&old_cycle->shm);
-        }
-
         ngx_destroy_pool(old_cycle->pool);
-
         cycle->old_cycle = NULL;
 
         return cycle;
@@ -630,10 +720,6 @@ failed:
 static void
 ngx_destroy_cycle_pools(ngx_conf_t *conf)
 {
-    if (conf->cycle->shm.addr) {
-        ngx_shm_free(&conf->cycle->shm);
-    }
-
     ngx_destroy_pool(conf->temp_pool);
     ngx_destroy_pool(conf->pool);
 }