diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-04-20 16:32:23 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-04-20 16:32:23 +0400 |
commit | 2d8eebcf7a0951d3d1189ddface7678fea76dd4c (patch) | |
tree | 7a1748e4d3633c3b8def3de8f2a08fb370c7e61d /src/lua/lua_common.c | |
parent | d4b35de4315753629ac5b107968e6194eac85d24 (diff) | |
download | rspamd-2d8eebcf7a0951d3d1189ddface7678fea76dd4c.tar.gz rspamd-2d8eebcf7a0951d3d1189ddface7678fea76dd4c.zip |
* Bugfixes:
- handle '\' characters in lua strings correctly
- fix lua initialization
- avoid of using global lua state (global L)
- fix listen sockets hash to allow multiply workers of same type but on different listen sockets
- fix modules options inserting to allow multiply options of the same name
- fix parsing of lua options
- fix lua rules
Diffstat (limited to 'src/lua/lua_common.c')
-rw-r--r-- | src/lua/lua_common.c | 54 |
1 files changed, 22 insertions, 32 deletions
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index dd79d9eab..fc5fe0772 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -28,7 +28,6 @@ /* Lua module init function */ #define MODULE_INIT_FUNC "module_init" -lua_State *L = NULL; const luaL_reg null_reg[] = { {"__tostring", lua_class_tostring}, {NULL, NULL} @@ -184,24 +183,25 @@ luaopen_logger (lua_State * L) void init_lua (struct config_file *cfg) { - if (L == NULL) { - L = lua_open (); - luaL_openlibs (L); - - (void)luaopen_rspamd (L); - (void)luaopen_logger (L); - (void)luaopen_config (L); - (void)luaopen_metric (L); - (void)luaopen_radix (L); - (void)luaopen_hash_table (L); - (void)luaopen_task (L); - (void)luaopen_textpart (L); - (void)luaopen_message (L); - (void)luaopen_classifier (L); - (void)luaopen_statfile (L); - cfg->lua_state = L; - memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func)lua_close, L); - } + lua_State *L; + + L = lua_open (); + luaL_openlibs (L); + + (void)luaopen_rspamd (L); + (void)luaopen_logger (L); + (void)luaopen_config (L); + (void)luaopen_metric (L); + (void)luaopen_radix (L); + (void)luaopen_hash_table (L); + (void)luaopen_task (L); + (void)luaopen_textpart (L); + (void)luaopen_message (L); + (void)luaopen_classifier (L); + (void)luaopen_statfile (L); + cfg->lua_state = L; + memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func)lua_close, L); + } @@ -213,6 +213,7 @@ init_lua_filters (struct config_file *cfg) GList *cur, *tmp; struct script_module *module; struct statfile *st; + lua_State *L = cfg->lua_state; cur = g_list_first (cfg->script_modules); while (cur) { @@ -413,23 +414,12 @@ lua_consolidation_func (struct worker_task *task, const char *metric_name, const return data.score; } -void -add_luabuf (const char *line) -{ - int error; - - error = luaL_loadbuffer (L, line, strlen (line), "config") || lua_pcall (L, 0, 0, 0); - if (error) { - yyerror ("lua error: %s", lua_tostring (L, -1)); - lua_pop (L, 1); /* pop error message from the stack */ - } -} - double -lua_normalizer_func (double score, void *params) +lua_normalizer_func (struct config_file *cfg, double score, void *params) { GList *p = params; double res = score; + lua_State *L = cfg->lua_state; /* Call specified function and put input score on stack */ if (!p->data) { |