[svn-commits] mnicholson: trunk r309543 - in /trunk: ./ pbx/pbx_lua.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Mar 4 13:02:33 CST 2011


Author: mnicholson
Date: Fri Mar  4 13:02:31 2011
New Revision: 309543

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=309543
Log:
Merged revisions 309542 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.8

................
  r309542 | mnicholson | 2011-03-04 13:00:33 -0600 (Fri, 04 Mar 2011) | 11 lines
  
  Merged revisions 309541 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.6.2
  
  ........
    r309541 | mnicholson | 2011-03-04 12:59:20 -0600 (Fri, 04 Mar 2011) | 4 lines
    
    Check for errors from fseek() when loading config file, properly abort on errors from fread(), and supply a traceback for errors generated when loading the config file.
    
    Also, prepend a newline to traceback output so that the main error message is on it's own line.
  ........
................

Modified:
    trunk/   (props changed)
    trunk/pbx/pbx_lua.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.8-merged' - no diff available.

Modified: trunk/pbx/pbx_lua.c
URL: http://svnview.digium.com/svn/asterisk/trunk/pbx/pbx_lua.c?view=diff&rev=309543&r1=309542&r2=309543
==============================================================================
--- trunk/pbx/pbx_lua.c (original)
+++ trunk/pbx/pbx_lua.c Fri Mar  4 13:02:31 2011
@@ -737,6 +737,9 @@
 	 * backtrace to it */
 	message_index = lua_gettop(L);
 
+	/* prepare to prepend a new line to the traceback */
+	lua_pushliteral(L, "\n");
+
 	lua_getglobal(L, "debug");
 	lua_getfield(L, -1, "traceback");
 	lua_remove(L, -2); /* remove the 'debug' table */
@@ -747,6 +750,9 @@
 	lua_pushnumber(L, 2);
 
 	lua_call(L, 2, 1);
+
+	/* prepend the new line we prepared above */
+	lua_concat(L, 2);
 
 	return 1;
 }
@@ -1001,6 +1007,7 @@
 static char *lua_read_extensions_file(lua_State *L, long *size)
 {
 	FILE *f;
+	int error_func;
 	char *data;
 	char *path = alloca(strlen(config) + strlen(ast_config_AST_CONFIG_DIR) + 2);
 	sprintf(path, "%s/%s", ast_config_AST_CONFIG_DIR, config);
@@ -1015,10 +1022,20 @@
 		return NULL;
 	}
 
-	fseek(f, 0l, SEEK_END);
+	if (fseek(f, 0l, SEEK_END)) {
+		fclose(f);
+		lua_pushliteral(L, "error determining the size of the config file");
+		return NULL;
+	}
+
 	*size = ftell(f);
 
-	fseek(f, 0l, SEEK_SET);
+	if (fseek(f, 0l, SEEK_SET)) {
+		*size = 0;
+		fclose(f);
+		lua_pushliteral(L, "error reading config file");
+		return NULL;
+	}
 
 	if (!(data = ast_malloc(*size))) {
 		*size = 0;
@@ -1028,12 +1045,18 @@
 	}
 
 	if (fread(data, sizeof(char), *size, f) != *size) {
-		ast_log(LOG_WARNING, "fread() failed: %s\n", strerror(errno));
+		*size = 0;
+		fclose(f);
+		lua_pushliteral(L, "problem reading configuration file");
+		return NULL;
 	}
 	fclose(f);
 
+	lua_pushcfunction(L, &lua_error_function);
+	error_func = lua_gettop(L);
+
 	if (luaL_loadbuffer(L, data, *size, "extensions.lua")
-			|| lua_pcall(L, 0, LUA_MULTRET, 0)
+			|| lua_pcall(L, 0, LUA_MULTRET, error_func)
 			|| lua_sort_extensions(L)
 			|| lua_register_switches(L)
 			|| lua_register_hints(L)) {
@@ -1041,6 +1064,8 @@
 		data = NULL;
 		*size = 0;
 	}
+
+	lua_remove(L, error_func);
 	return data;
 }
 




More information about the svn-commits mailing list