trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kic...@apache.org
Subject [trafficserver] branch master updated: Fix bug on loading of lua script
Date Wed, 11 Jul 2018 20:14:07 GMT
This is an automated email from the ASF dual-hosted git repository.

kichan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 3c0c413  Fix bug on loading of lua script
3c0c413 is described below

commit 3c0c413321d8fa59cbb4cc8f9e5ddbd9d5b04e98
Author: Kit Chan <kichan@apache.org>
AuthorDate: Tue Jul 10 00:13:46 2018 -0700

    Fix bug on loading of lua script
---
 plugins/lua/ts_lua.c        | 8 +++++---
 plugins/lua/ts_lua_common.h | 2 ++
 plugins/lua/ts_lua_util.c   | 3 +++
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/plugins/lua/ts_lua.c b/plugins/lua/ts_lua.c
index bd8cec2..cbfc782 100644
--- a/plugins/lua/ts_lua.c
+++ b/plugins/lua/ts_lua.c
@@ -133,8 +133,9 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int
errbuf_s
     }
 
     memset(conf, 0, sizeof(ts_lua_instance_conf));
-    conf->states = states;
-    conf->remap  = 1;
+    conf->states    = states;
+    conf->remap     = 1;
+    conf->init_func = 0;
 
     if (fn) {
       snprintf(conf->script, TS_LUA_MAX_SCRIPT_FNAME_LENGTH, "%s", argv[optind]);
@@ -150,7 +151,8 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int
errbuf_s
       return TS_ERROR;
     }
 
-    if (fn) {
+    // register the script only if it is from a file and has no __init__ function
+    if (fn && !conf->init_func) {
       // we only need to register the script for the first lua VM
       ts_lua_script_register(ts_lua_main_ctx_array[0].lua, conf->script, conf);
     }
diff --git a/plugins/lua/ts_lua_common.h b/plugins/lua/ts_lua_common.h
index e355e03..0115f0e 100644
--- a/plugins/lua/ts_lua_common.h
+++ b/plugins/lua/ts_lua_common.h
@@ -96,6 +96,8 @@ typedef struct {
 
   int remap;
   int states;
+
+  int init_func;
 } ts_lua_instance_conf;
 
 /* lua state for http request */
diff --git a/plugins/lua/ts_lua_util.c b/plugins/lua/ts_lua_util.c
index cb7d8c0..9455c1b 100644
--- a/plugins/lua/ts_lua_util.c
+++ b/plugins/lua/ts_lua_util.c
@@ -227,6 +227,9 @@ ts_lua_add_module(ts_lua_instance_conf *conf, ts_lua_main_ctx *arr, int
n, int a
     lua_getglobal(L, "__init__");
 
     if (lua_type(L, -1) == LUA_TFUNCTION) {
+      // specifying that the file has an __init__ function
+      conf->init_func = 1;
+
       lua_newtable(L);
 
       for (t = 0; t < argc; t++) {


Mime
View raw message