recreate the fifo on config load

This commit is contained in:
Gunter Labes 2008-09-04 17:28:26 +00:00
parent 34b6d36a0b
commit d3c0e61f4f

View File

@ -45,6 +45,7 @@
#include "forum_user_handler.hpp"
#endif
#include <boost/scoped_ptr.hpp>
#include <algorithm>
#include <cassert>
#include <cerrno>
@ -261,7 +262,7 @@ public:
class server
{
public:
server(int port, input_stream& input, const std::string& config_file, size_t min_threads,size_t max_threads);
server(int port, const std::string& config_file, size_t min_threads,size_t max_threads);
void run();
private:
void send_error(network::connection sock, const char* msg) const;
@ -288,7 +289,7 @@ private:
wesnothd::game lobby_;
//! server socket/fifo
input_stream& input_;
boost::scoped_ptr<input_stream> input_;
const std::string config_file_;
config cfg_;
@ -356,8 +357,8 @@ private:
void start_new_server();
};
server::server(int port, input_stream& input, const std::string& config_file,
size_t min_threads,size_t max_threads) :
server::server(int port, const std::string& config_file, size_t min_threads,
size_t max_threads) :
net_manager_(min_threads,max_threads),
server_(port),
ban_manager_(),
@ -368,7 +369,7 @@ server::server(int port, input_stream& input, const std::string& config_file,
games_(),
not_logged_in_(players_),
lobby_(players_),
input_(input),
input_(),
config_file_(config_file),
cfg_(read_config()),
accepted_versions_(),
@ -487,6 +488,14 @@ config server::read_config() const {
}
void server::load_config() {
#ifndef FIFODIR
# warning "No FIFODIR set"
# define FIFODIR "/var/run/wesnothd"
#endif
const std::string fifo_path = (cfg_["fifo_path"].empty() ? std::string(FIFODIR) + "/socket" : std::string(cfg_["fifo_path"]));
input_.reset();
input_.reset(new input_stream(fifo_path));
admin_passwd_ = cfg_["passwd"];
motd_ = cfg_["motd"];
lan_server_ = lexical_cast_default<time_t>(cfg_["lan_server"], 0);
@ -612,7 +621,7 @@ void server::run() {
// Process commands from the server socket/fifo
std::string admin_cmd;
if (input_.read_line(admin_cmd)) {
if (input_ && input_->read_line(admin_cmd)) {
process_command(admin_cmd, "*socket*");
}
@ -1163,7 +1172,7 @@ std::string server::process_command(const std::string& query, const std::string&
} else {
// Graceful shut down.
server_.stop();
input_.stop();
input_.reset();
graceful_restart = true;
process_command("msg The server is shutting down. You may finish your games but can't start new ones. Once all games have ended the server will exit.", issuer_name);
out << "Server is doing graceful shut down.";
@ -1179,7 +1188,7 @@ std::string server::process_command(const std::string& query, const std::string&
graceful_restart = true;
// stop listening socket
server_.stop();
input_.stop();
input_.reset();
// start new server
start_new_server();
process_command("msg The server has been restarted. You may finish your games but can't start new ones and new players can't join this server.", issuer_name);
@ -2108,12 +2117,6 @@ int main(int argc, char** argv) {
std::string config_file;
#ifndef FIFODIR
# warning "No FIFODIR set"
# define FIFODIR "/var/run/wesnothd"
#endif
std::string fifo_path = std::string(FIFODIR) + "/socket";
// setting path to currentworking directory
game_config::path = get_cwd();
@ -2210,12 +2213,11 @@ int main(int argc, char** argv) {
port = atoi(argv[arg]);
}
}
input_stream input(fifo_path);
network::set_raw_data_only();
try {
server(port, input, config_file, min_threads, max_threads).run();
server(port, config_file, min_threads, max_threads).run();
} catch(network::error& e) {
ERR_SERVER << "Caught network error while server was running. Aborting.: "
<< e.message << "\n";