diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-07-09 16:34:41 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-07-09 16:34:41 +0100 |
commit | 5673dffb28edf9d64642db09fcd7b624a89e5fef (patch) | |
tree | 7d1cf356fdacd05d8949912fe8a1cb30f7ca7c8a /src | |
parent | 7ba5acbc01a5b5bdb436df1c57cf2c6c86897838 (diff) | |
download | rspamd-5673dffb28edf9d64642db09fcd7b624a89e5fef.tar.gz rspamd-5673dffb28edf9d64642db09fcd7b624a89e5fef.zip |
[Minor] Print traceback on lua_redis callback errors
Diffstat (limited to 'src')
-rw-r--r-- | src/lua/lua_redis.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c index 003538b1a..ac1a8c297 100644 --- a/src/lua/lua_redis.c +++ b/src/lua/lua_redis.c @@ -275,12 +275,16 @@ lua_redis_push_error (const gchar *err, { struct lua_redis_userdata *ud = sp_ud->c; struct lua_callback_state cbs; + lua_State *L; if (!(sp_ud->flags & (LUA_REDIS_SPECIFIC_REPLIED|LUA_REDIS_SPECIFIC_FINISHED))) { if (sp_ud->cbref != -1) { lua_thread_pool_prepare_callback (ud->cfg->lua_thread_pool, &cbs); + L = cbs.L; + lua_pushcfunction (L, &rspamd_lua_traceback); + int err_idx = lua_gettop (L); /* Push error */ lua_rawgeti (cbs.L, LUA_REGISTRYINDEX, sp_ud->cbref); @@ -293,11 +297,11 @@ lua_redis_push_error (const gchar *err, rspamd_symcache_set_cur_item (ud->task, ud->item); } - if (lua_pcall (cbs.L, 2, 0, 0) != 0) { + if (lua_pcall (cbs.L, 2, 0, err_idx) != 0) { msg_info ("call to callback failed: %s", lua_tostring (cbs.L, -1)); - lua_pop (cbs.L, 1); } + lua_settop (L, err_idx - 1); lua_thread_pool_restore_callback (&cbs); } @@ -367,11 +371,15 @@ lua_redis_push_data (const redisReply *r, struct lua_redis_ctx *ctx, { struct lua_redis_userdata *ud = sp_ud->c; struct lua_callback_state cbs; + lua_State *L; if (!(sp_ud->flags & (LUA_REDIS_SPECIFIC_REPLIED|LUA_REDIS_SPECIFIC_FINISHED))) { if (sp_ud->cbref != -1) { lua_thread_pool_prepare_callback (ud->cfg->lua_thread_pool, &cbs); + L = cbs.L; + lua_pushcfunction (L, &rspamd_lua_traceback); + int err_idx = lua_gettop (L); /* Push error */ lua_rawgeti (cbs.L, LUA_REGISTRYINDEX, sp_ud->cbref); /* Error is nil */ @@ -383,11 +391,11 @@ lua_redis_push_data (const redisReply *r, struct lua_redis_ctx *ctx, rspamd_symcache_set_cur_item (ud->task, ud->item); } - if (lua_pcall (cbs.L, 2, 0, 0) != 0) { + if (lua_pcall (cbs.L, 2, 0, err_idx) != 0) { msg_info ("call to callback failed: %s", lua_tostring (cbs.L, -1)); - lua_pop (cbs.L, 1); } + lua_settop (L, err_idx - 1); lua_thread_pool_restore_callback (&cbs); } |