diff options
author | Mikhail Galanin <mgalanin@mimecast.com> | 2018-08-17 11:18:41 +0100 |
---|---|---|
committer | Mikhail Galanin <mgalanin@mimecast.com> | 2018-08-17 11:18:41 +0100 |
commit | ac7cb176fd1eb72a891e4c245d1094c0175a1bad (patch) | |
tree | f29499817f2c59be957851c6f0effdaf4bb85084 /src | |
parent | 15c7adc671c7d8e22febab8e64e946f71e93738c (diff) | |
download | rspamd-ac7cb176fd1eb72a891e4c245d1094c0175a1bad.tar.gz rspamd-ac7cb176fd1eb72a891e4c245d1094c0175a1bad.zip |
[Minor] Small improvements
Diffstat (limited to 'src')
-rw-r--r-- | src/lua/lua_common.c | 16 | ||||
-rw-r--r-- | src/lua/lua_common.h | 8 | ||||
-rw-r--r-- | src/lua/lua_config.c | 12 |
3 files changed, 30 insertions, 6 deletions
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 @@ -337,6 +337,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` */ guint rspamd_lua_table_size (lua_State *L, gint 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 */ |