]> source.dussan.org Git - rspamd.git/commitdiff
Print traceback on lua errors in lua config
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 5 Feb 2016 11:30:45 +0000 (11:30 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 5 Feb 2016 13:38:57 +0000 (13:38 +0000)
src/libserver/cfg_rcl.c

index 7dd6626cd110628074adc7ce63a6876b94da5928..df9768792fae17d6253b02e155a2de65f8c79c74 100644 (file)
@@ -729,6 +729,8 @@ rspamd_rcl_lua_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
                        ucl_object_tostring (obj));
        gchar *cur_dir, *lua_dir, *lua_file, *tmp1, *tmp2;
        lua_State *L = cfg->lua_state;
+       GString *tb;
+       gint err_idx;
 
        tmp1 = g_strdup (lua_src);
        tmp2 = g_strdup (lua_src);
@@ -738,6 +740,10 @@ rspamd_rcl_lua_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
        if (lua_dir && lua_file) {
                cur_dir = g_malloc (PATH_MAX);
                if (getcwd (cur_dir, PATH_MAX) != NULL && chdir (lua_dir) != -1) {
+                       /* Push traceback function */
+                       lua_pushcfunction (L, &rspamd_lua_traceback);
+                       err_idx = lua_gettop (L);
+
                        /* Load file */
                        if (luaL_loadfile (L, lua_file) != 0) {
                                g_set_error (err,
@@ -755,23 +761,32 @@ rspamd_rcl_lua_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
                                g_free (tmp2);
                                return FALSE;
                        }
+
                        /* Now do it */
-                       if (lua_pcall (L, 0, LUA_MULTRET, 0) != 0) {
+                       if (lua_pcall (L, 0, 0, err_idx) != 0) {
+                               tb = lua_touserdata (L, -1);
                                g_set_error (err,
-                                       CFG_RCL_ERROR,
-                                       EINVAL,
-                                       "cannot init lua file %s: %s",
-                                       lua_src,
-                                       lua_tostring (L, -1));
+                                               CFG_RCL_ERROR,
+                                               EINVAL,
+                                               "cannot init lua file %s: %s",
+                                               lua_src,
+                                               tb->str);
+                               g_string_free (tb, TRUE);
+                               lua_pop (L, 1);
+
                                if (chdir (cur_dir) == -1) {
                                        msg_err_config ("cannot chdir to %s: %s", cur_dir,
                                                strerror (errno));
                                }
+
                                g_free (cur_dir);
                                g_free (tmp1);
                                g_free (tmp2);
+
                                return FALSE;
                        }
+
+                       lua_pop (L, 1);
                }
                else {
                        g_set_error (err, CFG_RCL_ERROR, ENOENT, "cannot chdir to %s: %s",