Skip to content

Move init #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: init
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions src/ngx_http_lua_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ ngx_http_lua_shared_memory_add(ngx_conf_t *cf, ngx_str_t *name, size_t size,
zone->init = ngx_http_lua_shared_memory_init;
zone->data = ctx;

lmcf->requires_shm = 1;

return &ctx->zone;
}

Expand All @@ -159,8 +157,6 @@ ngx_http_lua_shared_memory_init(ngx_shm_zone_t *shm_zone, void *data)
ngx_shm_zone_t *ozone;
void *odata;

ngx_int_t rc;
volatile ngx_cycle_t *saved_cycle;
ngx_http_lua_main_conf_t *lmcf;
ngx_http_lua_shm_zone_ctx_t *ctx;
ngx_shm_zone_t *zone;
Expand Down Expand Up @@ -194,22 +190,6 @@ ngx_http_lua_shared_memory_init(ngx_shm_zone_t *shm_zone, void *data)

lmcf->shm_zones_inited++;

if (lmcf->shm_zones_inited == lmcf->shm_zones->nelts
&& lmcf->init_handler)
{
saved_cycle = ngx_cycle;
ngx_cycle = ctx->cycle;

rc = lmcf->init_handler(ctx->log, lmcf, lmcf->lua);

ngx_cycle = saved_cycle;

if (rc != NGX_OK) {
/* an error happened */
return NGX_ERROR;
}
}

return NGX_OK;
}

Expand Down
1 change: 0 additions & 1 deletion src/ngx_http_lua_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ struct ngx_http_lua_main_conf_s {
unsigned requires_rewrite:1;
unsigned requires_access:1;
unsigned requires_log:1;
unsigned requires_shm:1;
};


Expand Down
2 changes: 0 additions & 2 deletions src/ngx_http_lua_directive.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ ngx_http_lua_shared_dict(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)

*zp = zone;

lmcf->requires_shm = 1;

return NGX_CONF_OK;
}

Expand Down
29 changes: 29 additions & 0 deletions src/ngx_http_lua_initby.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,35 @@
#include "ngx_http_lua_util.h"


ngx_int_t
ngx_http_lua_init_module(ngx_cycle_t *cycle)
{
ngx_int_t rc;
ngx_http_lua_main_conf_t *lmcf;
volatile ngx_cycle_t *saved_cycle;

lmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_lua_module);

if (lmcf == NULL || lmcf->init_handler == NULL || lmcf->lua == NULL) {
return NGX_OK;
}

saved_cycle = ngx_cycle;
ngx_cycle = cycle;

rc = lmcf->init_handler(cycle->log, lmcf, lmcf->lua);

ngx_cycle = saved_cycle;

if (rc != NGX_OK) {
/* an error happened */
return NGX_ERROR;
}

return NGX_OK;
}


ngx_int_t
ngx_http_lua_init_by_inline(ngx_log_t *log, ngx_http_lua_main_conf_t *lmcf,
lua_State *L)
Expand Down
2 changes: 2 additions & 0 deletions src/ngx_http_lua_initby.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ ngx_int_t ngx_http_lua_init_by_inline(ngx_log_t *log,
ngx_int_t ngx_http_lua_init_by_file(ngx_log_t *log,
ngx_http_lua_main_conf_t *lmcf, lua_State *L);

ngx_int_t ngx_http_lua_init_module(ngx_cycle_t *cycle);


#endif /* _NGX_HTTP_LUA_INITBY_H_INCLUDED_ */

Expand Down
18 changes: 1 addition & 17 deletions src/ngx_http_lua_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ ngx_module_t ngx_http_lua_module = {
ngx_http_lua_cmds, /* module directives */
NGX_HTTP_MODULE, /* module type */
NULL, /* init master */
NULL, /* init module */
ngx_http_lua_init_module, /* init module */
ngx_http_lua_init_worker, /* init process */
NULL, /* init thread */
NULL, /* exit thread */
Expand All @@ -635,7 +635,6 @@ ngx_http_lua_init(ngx_conf_t *cf)
ngx_int_t rc;
ngx_array_t *arr;
ngx_http_handler_pt *h;
volatile ngx_cycle_t *saved_cycle;
ngx_http_core_main_conf_t *cmcf;
ngx_http_lua_main_conf_t *lmcf;
#ifndef NGX_LUA_NO_FFI_API
Expand Down Expand Up @@ -745,20 +744,6 @@ ngx_http_lua_init(ngx_conf_t *cf)
return NGX_ERROR;
}

if (!lmcf->requires_shm && lmcf->init_handler) {
saved_cycle = ngx_cycle;
ngx_cycle = cf->cycle;

rc = lmcf->init_handler(cf->log, lmcf, lmcf->lua);

ngx_cycle = saved_cycle;

if (rc != NGX_OK) {
/* an error happened */
return NGX_ERROR;
}
}

dd("Lua VM initialized!");
}

Expand Down Expand Up @@ -829,7 +814,6 @@ ngx_http_lua_create_main_conf(ngx_conf_t *cf)
* lmcf->requires_rewrite = 0;
* lmcf->requires_access = 0;
* lmcf->requires_log = 0;
* lmcf->requires_shm = 0;
*/

lmcf->pool = cf->pool;
Expand Down