summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Borisov <borisov.alexandr@rambler.ru>2011-12-03 16:01:22 +0200
committerAlex Borisov <borisov.alexandr@rambler.ru>2011-12-03 16:01:22 +0200
commit0995dea3bba87cdd181fafb70feb2c46b7c17864 (patch)
treef9b5fed10040cf01e02c473d40127cc6ecb6c6c8
parentf6cd6fd75ba16accbb165b8261f429b899ea2d14 (diff)
Fix startup segfault when config.cfg not present
-rw-r--r--client/Config.cpp2
-rw-r--r--client/ProxyClientApp.cpp10
-rw-r--r--client/UpdatedConfig.cpp8
3 files changed, 18 insertions, 2 deletions
diff --git a/client/Config.cpp b/client/Config.cpp
index 7cfc4fb..40c24b2 100644
--- a/client/Config.cpp
+++ b/client/Config.cpp
@@ -98,7 +98,7 @@ Config::Config(): StaticProxySpeedLow(50)
Logger::Info("Parsing config.cfg to determine initial configuration\n");
QString configPath = this_app->applicationDirPath()+ "/config.cfg";
ifstream configFile(configPath.toLocal8Bit().data(), std::ios::in);
- if (!configFile)
+ if (!configFile.is_open())
{
Logger::Fatal("Can't open file: config.cfg\n");
return;
diff --git a/client/ProxyClientApp.cpp b/client/ProxyClientApp.cpp
index e2968b0..4bc5648 100644
--- a/client/ProxyClientApp.cpp
+++ b/client/ProxyClientApp.cpp
@@ -12,6 +12,16 @@ using namespace std;
ProxyClientApp::ProxyClientApp(int &argc, char *argv[]): QApplication(argc, argv)
{
+ // check if initial config exists (config.cfg)
+ QString configPath = this_app->applicationDirPath()+ "/config.cfg";
+ QFileInfo configInfo(configPath);
+ if (! configInfo.exists())
+ {
+ Logger::Fatal("Initial configuration file (config.cfg) do not exist!\n");
+ Logger::Fatal("Terminating!\n");
+ return ;
+ }
+
/* initiates UpdatedConfig singleton that start sending configuration requests */
UpdatedConfig *cfg = UpdatedConfig::CurrentConfig();
connect(cfg, SIGNAL(updated()),
diff --git a/client/UpdatedConfig.cpp b/client/UpdatedConfig.cpp
index 9cf91dd..ac8ec10 100644
--- a/client/UpdatedConfig.cpp
+++ b/client/UpdatedConfig.cpp
@@ -27,7 +27,13 @@ UpdatedConfig::UpdatedConfig()
activeSrvIndex = 0;
time = 0;
retryFailed = false;
-
+
+ if (servers.size() == 0)
+ {
+ Logger::Error("No server records present. Can't update configuration!\n");
+ return;
+ }
+
client = new SslClient(QString::fromStdString(servers[0].host));
connect(client, SIGNAL(ReplyRecieved(SslClient::RequestType&, QByteArray&)),
this, SLOT(gotServerReply(SslClient::RequestType&, QByteArray&)));