Skip to content

Commit

Permalink
Core: provided access to previous cycle shared memory zone data.
Browse files Browse the repository at this point in the history
Currently, the data of shared memory zone with 'noreuse' flag
is not accessible by zone init handler of the new cycle.

The patch makes the pointer to the old zone available during the new
zone initialization, thus allowing for the module to inherit required data.
  • Loading branch information
vlhomutov committed Dec 28, 2022
1 parent a20e758 commit 4f326ea
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/core/ngx_cycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static ngx_connection_t dumb;
ngx_cycle_t *
ngx_init_cycle(ngx_cycle_t *old_cycle)
{
void *rv;
void *rv, *old_data;
char **senv;
ngx_uint_t i, n;
ngx_log_t *log;
Expand Down Expand Up @@ -446,6 +446,8 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
opart = &old_cycle->shared_memory.part;
oshm_zone = opart->elts;

old_data = NULL;

for (n = 0; /* void */ ; n++) {

if (n >= opart->nelts) {
Expand All @@ -469,10 +471,16 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
continue;
}

if (shm_zone[i].tag == oshm_zone[n].tag
&& shm_zone[i].shm.size == oshm_zone[n].shm.size
&& !shm_zone[i].noreuse)
{
if (shm_zone[i].tag != oshm_zone[n].tag) {
break;
}

if (shm_zone[i].noreuse) {
old_data = oshm_zone[n].data;
break;
}

if (shm_zone[i].shm.size == oshm_zone[n].shm.size) {
shm_zone[i].shm.addr = oshm_zone[n].shm.addr;
#if (NGX_WIN32)
shm_zone[i].shm.handle = oshm_zone[n].shm.handle;
Expand All @@ -498,7 +506,7 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
goto failed;
}

if (shm_zone[i].init(&shm_zone[i], NULL) != NGX_OK) {
if (shm_zone[i].init(&shm_zone[i], old_data) != NGX_OK) {
goto failed;
}

Expand Down

0 comments on commit 4f326ea

Please sign in to comment.