Skip to content

Commit

Permalink
bugfix: init_by_lua* might be skipped altogether when HUP config relo…
Browse files Browse the repository at this point in the history
…ad was used.
  • Loading branch information
agentzh committed Jul 3, 2012
1 parent 5445e0e commit ce4314d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ngx_http_lua_directive.c
Expand Up @@ -72,7 +72,7 @@ ngx_http_lua_shared_dict(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)


ctx->name = name; ctx->name = name;
ctx->main_conf = lmcf; ctx->main_conf = lmcf;
ctx->log = cf->log; ctx->log = &cf->cycle->new_log;


zone = ngx_shared_memory_add(cf, &name, (size_t) size, zone = ngx_shared_memory_add(cf, &name, (size_t) size,
&ngx_http_lua_module); &ngx_http_lua_module);
Expand Down
6 changes: 3 additions & 3 deletions src/ngx_http_lua_shdict.c
Expand Up @@ -44,17 +44,16 @@ ngx_http_lua_shdict_init_zone(ngx_shm_zone_t *shm_zone, void *data)
if (octx) { if (octx) {
ctx->sh = octx->sh; ctx->sh = octx->sh;
ctx->shpool = octx->shpool; ctx->shpool = octx->shpool;
ctx->log = octx->log;


return NGX_OK; goto done;
} }


ctx->shpool = (ngx_slab_pool_t *) shm_zone->shm.addr; ctx->shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;


if (shm_zone->shm.exists) { if (shm_zone->shm.exists) {
ctx->sh = ctx->shpool->data; ctx->sh = ctx->shpool->data;


return NGX_OK; goto done;
} }


ctx->sh = ngx_slab_alloc(ctx->shpool, sizeof(ngx_http_lua_shdict_shctx_t)); ctx->sh = ngx_slab_alloc(ctx->shpool, sizeof(ngx_http_lua_shdict_shctx_t));
Expand All @@ -79,6 +78,7 @@ ngx_http_lua_shdict_init_zone(ngx_shm_zone_t *shm_zone, void *data)
ngx_sprintf(ctx->shpool->log_ctx, " in lua_shared_dict zone \"%V\"%Z", ngx_sprintf(ctx->shpool->log_ctx, " in lua_shared_dict zone \"%V\"%Z",
&shm_zone->shm.name); &shm_zone->shm.name);


done:
dd("get lmcf"); dd("get lmcf");


lmcf = ctx->main_conf; lmcf = ctx->main_conf;
Expand Down
29 changes: 29 additions & 0 deletions t/086-init-by.t
Expand Up @@ -13,6 +13,8 @@ plan tests => repeat_each() * (blocks() * 3);


#no_diff(); #no_diff();
#no_long_string(); #no_long_string();
no_shuffle();

run_tests(); run_tests();


__DATA__ __DATA__
Expand Down Expand Up @@ -168,3 +170,30 @@ ok
--- error_log --- error_log
log from init_by_lua log from init_by_lua




=== TEST 8: require (with shm defined)
--- http_config
lua_package_path "$prefix/html/?.lua;;";
lua_shared_dict dogs 1m;
init_by_lua 'require "blah"';
--- config
location /lua {
content_by_lua '
blah.go()
';
}
--- user_files
>>> blah.lua
module(..., package.seeall)

function go()
ngx.say("hello, blah")
end
--- request
GET /lua
--- response_body
hello, blah
--- no_error_log
[error]

0 comments on commit ce4314d

Please sign in to comment.