diff --git a/src/scripting.c b/src/scripting.c index 0abfe165..339f6eef 100644 --- a/src/scripting.c +++ b/src/scripting.c @@ -790,12 +790,26 @@ void scriptingEnableGlobalsProtection(lua_State *lua) { } /* Initialize the scripting environment. - * It is possible to call this function to reset the scripting environment - * assuming that we call scriptingRelease() before. - * See scriptingReset() for more information. */ -void scriptingInit(void) { + * + * This function is called the first time at server startup with + * the 'setup' argument set to 1. + * + * It can be called again multiple times during the lifetime of the Redis + * process, with 'setup' set to 0, and following a scriptingRelease() call, + * in order to reset the Lua scripting environment. + * + * However it is simpler to just call scriptingReset() that does just that. */ +void scriptingInit(int setup) { lua_State *lua = lua_open(); + if (setup) { + server.lua_client = NULL; + server.lua_caller = NULL; + server.lua_timedout = 0; + server.lua_always_replicate_commands = 0; /* Only DEBUG can change it.*/ + server.lua_time_limit = LUA_SCRIPT_TIME_LIMIT; + } + luaLoadLibraries(lua); luaRemoveUnsupportedFunctions(lua); @@ -952,7 +966,7 @@ void scriptingRelease(void) { void scriptingReset(void) { scriptingRelease(); - scriptingInit(); + scriptingInit(0); } /* Set an array of Redis String Objects as a Lua array (table) stored into a @@ -1011,6 +1025,15 @@ int redis_math_randomseed (lua_State *L) { return 0; } +/* --------------------------------------------------------------------------- + * LDB: Redis Lua debugging facilities + * ------------------------------------------------------------------------- */ + +/* Enable debug mode of Lua scripts for this client. */ +void ldbEnable(client *c) { + c->flags |= CLIENT_LUA_DEBUG; +} + /* --------------------------------------------------------------------------- * EVAL and SCRIPT commands implementation * ------------------------------------------------------------------------- */ @@ -1331,6 +1354,9 @@ void scriptCommand(client *c) { server.lua_kill = 1; addReply(c,shared.ok); } + } else if (c->argc == 2 && !strcasecmp(c->argv[1]->ptr,"debug")) { + ldbEnable(c); + addReply(c,shared.ok); } else { addReplyError(c, "Unknown SCRIPT subcommand or wrong # of args."); } diff --git a/src/server.c b/src/server.c index 9bcf11e8..ccd7cf5c 100644 --- a/src/server.c +++ b/src/server.c @@ -1508,11 +1508,6 @@ void initServerConfig(void) { server.cluster_slave_validity_factor = CLUSTER_DEFAULT_SLAVE_VALIDITY; server.cluster_require_full_coverage = CLUSTER_DEFAULT_REQUIRE_FULL_COVERAGE; server.cluster_configfile = zstrdup(CONFIG_DEFAULT_CLUSTER_CONFIG_FILE); - server.lua_caller = NULL; - server.lua_time_limit = LUA_SCRIPT_TIME_LIMIT; - server.lua_client = NULL; - server.lua_timedout = 0; - server.lua_always_replicate_commands = 0; /* Only DEBUG can change it. */ server.migrate_cached_sockets = dictCreate(&migrateCacheDictType,NULL); server.next_client_id = 1; /* Client IDs, start from 1 .*/ server.loading_process_events_interval_bytes = (1024*1024*2); @@ -1973,7 +1968,7 @@ void initServer(void) { if (server.cluster_enabled) clusterInit(); replicationScriptCacheInit(); - scriptingInit(); + scriptingInit(1); slowlogInit(); latencyMonitorInit(); bioInit(); diff --git a/src/server.h b/src/server.h index 3fb5afa7..d549191a 100644 --- a/src/server.h +++ b/src/server.h @@ -1468,7 +1468,7 @@ int redis_check_rdb(char *rdbfilename); int redis_check_rdb_main(char **argv, int argc); /* Scripting */ -void scriptingInit(void); +void scriptingInit(int setup); /* Blocked clients */ void processUnblockedClients(void);