From: Mikhail Galanin Date: Fri, 17 Aug 2018 10:18:41 +0000 (+0100) Subject: [Minor] Small improvements X-Git-Tag: 1.8.0~234^2~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ac7cb176fd1eb72a891e4c245d1094c0175a1bad;p=rspamd.git [Minor] Small improvements --- diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index 63a95f177..5c9e4f4b3 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -1494,14 +1494,26 @@ rspamd_lua_traceback (lua_State *L) { GString *tb; + + tb = rspamd_lua_get_traceback_string (L); + + lua_pushlightuserdata (L, tb); + + return 1; +} + +GString * +rspamd_lua_get_traceback_string (lua_State *L) +{ + GString *tb; const gchar *msg = lua_tostring (L, 1); tb = g_string_sized_new (100); g_string_append_printf (tb, "%s; trace:", msg); + rspamd_lua_traceback_string (L, tb); - lua_pushlightuserdata (L, tb); - return 1; + return tb; } guint diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index cf171c313..fd5b7a276 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -336,6 +336,14 @@ gboolean rspamd_lua_parse_table_arguments (lua_State *L, gint pos, gint rspamd_lua_traceback (lua_State *L); +/** + * Returns stack trace as a string. Caller should clear memory. + * @param L + * @return + */ +GString * +rspamd_lua_get_traceback_string (lua_State *L); + /** * Returns size of table at position `tbl_pos` */ diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index f02ec32da..6957ded7c 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -1257,6 +1257,13 @@ lua_resume_thread (struct rspamd_task *task, struct thread_entry *thread_entry, { g_assert (thread_entry->cd != NULL); + /* + * The only state where we can resume from is LUA_YIELD + * Another acceptable status is OK (0) but in that case we should push function on stack + * to start the thread from, which is happening in lua_metric_symbol_callback(), not in this function. + */ + g_assert (lua_status (thread_entry->lua_state) == LUA_YIELD); + gint ret; lua_thread_pool_set_running_entry (task->cfg->lua_thread_pool, thread_entry); @@ -1277,15 +1284,12 @@ lua_metric_symbol_callback_return (struct rspamd_task *task, struct thread_entry lua_State *thread = thread_entry->lua_state; if (ret != 0) { - lua_pushcfunction (thread, rspamd_lua_traceback); - lua_call (thread, 0, LUA_MULTRET); - tb = lua_touserdata (thread, -1); + tb = rspamd_lua_get_traceback_string (thread); msg_err_task ("call to (%s) failed (%d): %v", cd->symbol, ret, tb); if (tb) { g_string_free (tb, TRUE); - lua_pop (thread, 1); } g_assert (lua_gettop (thread) >= cd->stack_level); /* maybe there is a way to recover here. For now, just remove faulty thread */