summaryrefslogtreecommitdiff
path: root/src/server.cpp
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2015-10-29 14:48:10 -0400
committerShadowNinja <shadowninja@minetest.net>2015-10-31 13:28:58 -0400
commit9269a0ecc7267822bc5ac5af95ad4977bdc94fec (patch)
tree1cf8639cc0a6b367670ac673780f321f85b467be /src/server.cpp
parentb872df6ef6a15ae4624b35ea7b8960bc24da1128 (diff)
downloadminetest-9269a0ecc7267822bc5ac5af95ad4977bdc94fec.tar.gz
minetest-9269a0ecc7267822bc5ac5af95ad4977bdc94fec.tar.bz2
minetest-9269a0ecc7267822bc5ac5af95ad4977bdc94fec.zip
Fix server crashing on Lua errors
Previously, the server called FATAL_ERROR when a Lua error occured. This caused a (mostly useless) core dump. The server now simply throws an exception, which is caught and printed before exiting with a non-zero return value. This also fixes a number of instances where errors were logged multiple times.
Diffstat (limited to 'src/server.cpp')
-rw-r--r--src/server.cpp43
1 files changed, 13 insertions, 30 deletions
diff --git a/src/server.cpp b/src/server.cpp
index 09675dae3..327591c60 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -276,11 +276,8 @@ Server::Server(
m_script = new GameScripting(this);
std::string script_path = getBuiltinLuaPath() + DIR_DELIM "init.lua";
- std::string error_msg;
- if (!m_script->loadMod(script_path, BUILTIN_MOD_NAME, &error_msg))
- throw ModError("Failed to load and run " + script_path
- + "\nError from Lua:\n" + error_msg);
+ m_script->loadMod(script_path, BUILTIN_MOD_NAME);
// Print mods
infostream << "Server: Loading mods: ";
@@ -291,26 +288,18 @@ Server::Server(
}
infostream << std::endl;
// Load and run "mod" scripts
- for (std::vector<ModSpec>::iterator i = m_mods.begin();
- i != m_mods.end(); ++i) {
- const ModSpec &mod = *i;
+ for (std::vector<ModSpec>::iterator it = m_mods.begin();
+ it != m_mods.end(); ++it) {
+ const ModSpec &mod = *it;
if (!string_allowed(mod.name, MODNAME_ALLOWED_CHARS)) {
- std::ostringstream err;
- err << "Error loading mod \"" << mod.name
- << "\": mod_name does not follow naming conventions: "
- << "Only chararacters [a-z0-9_] are allowed." << std::endl;
- errorstream << err.str().c_str();
- throw ModError(err.str());
+ throw ModError("Error loading mod \"" + mod.name +
+ "\": Mod name does not follow naming conventions: "
+ "Only chararacters [a-z0-9_] are allowed.");
}
- std::string script_path = mod.path + DIR_DELIM "init.lua";
+ std::string script_path = mod.path + DIR_DELIM + "init.lua";
infostream << " [" << padStringRight(mod.name, 12) << "] [\""
<< script_path << "\"]" << std::endl;
- if (!m_script->loadMod(script_path, mod.name, &error_msg)) {
- errorstream << "Server: Failed to load and run "
- << script_path << std::endl;
- throw ModError("Failed to load and run " + script_path
- + "\nError from Lua:\n" + error_msg);
- }
+ m_script->loadMod(script_path, mod.name);
}
// Read Textures and calculate sha1 sums
@@ -483,7 +472,7 @@ void Server::step(float dtime)
{
DSTACK(FUNCTION_NAME);
// Limit a bit
- if(dtime > 2.0)
+ if (dtime > 2.0)
dtime = 2.0;
{
MutexAutoLock lock(m_step_dtime_mutex);
@@ -491,19 +480,13 @@ void Server::step(float dtime)
}
// Throw if fatal error occurred in thread
std::string async_err = m_async_fatal_error.get();
- if(async_err != "") {
- if (m_simple_singleplayer_mode) {
- throw ServerError(async_err);
- }
- else {
+ if (!async_err.empty()) {
+ if (!m_simple_singleplayer_mode) {
m_env->kickAllPlayers(SERVER_ACCESSDENIED_CRASH,
g_settings->get("kick_msg_crash"),
g_settings->getBool("ask_reconnect_on_crash"));
- errorstream << "UNRECOVERABLE error occurred. Stopping server. "
- << "Please fix the following error:" << std::endl
- << async_err << std::endl;
- FATAL_ERROR(async_err.c_str());
}
+ throw ServerError(async_err);
}
}