commit 5673dff: [Minor] Print traceback on lua_redis callback errors
Vsevolod Stakhov
vsevolod at highsecure.ru
Tue Jul 9 15:42:05 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-07-09 16:34:41 +0100
URL: https://github.com/rspamd/rspamd/commit/5673dffb28edf9d64642db09fcd7b624a89e5fef (HEAD -> master)
[Minor] Print traceback on lua_redis callback errors
---
src/lua/lua_redis.c | 16 ++++++++++++----
1 file 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);
}
More information about the Commits
mailing list