summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2018-08-06 21:14:05 +0200
committerlouiz’ <louiz@louiz.org>2018-08-07 20:49:34 +0200
commit9fa7591058f8e4b32f64a2b61fe85c277cf2a9d9 (patch)
tree33ca4396050c570fcd0053c81ae6a05f9f229b68 /src
parent89ad479ef40a6a2363ea6aa80861f91cc2eddcd4 (diff)
downloadbiboumi-9fa7591058f8e4b32f64a2b61fe85c277cf2a9d9.tar.gz
biboumi-9fa7591058f8e4b32f64a2b61fe85c277cf2a9d9.tar.bz2
biboumi-9fa7591058f8e4b32f64a2b61fe85c277cf2a9d9.tar.xz
biboumi-9fa7591058f8e4b32f64a2b61fe85c277cf2a9d9.zip
Split the main() into smaller functions
That’s not really enough, but better
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp94
1 files changed, 54 insertions, 40 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 09adc5c..04500b7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -55,45 +55,8 @@ static void sigusr_handler(int, siginfo_t*, void*)
reload.store(true);
}
-int main(int ac, char** av)
+static void setup_signals()
{
- if (ac > 1)
- {
- const std::string arg = av[1];
- if (arg.size() >= 2 && arg[0] == '-' && arg[1] == '-')
- {
- if (arg == "--help")
- return display_help();
- else
- {
- std::cerr << "Unknow command line option: " << arg << std::endl;
- return 1;
- }
- }
- }
- const std::string conf_filename = ac > 1 ? av[1] : xdg_config_path("biboumi.cfg");
- std::cout << "Using configuration file: " << conf_filename << std::endl;
-
- if (!Config::read_conf(conf_filename))
- return config_help("");
-
- const std::string password = Config::get("password", "");
- if (password.empty())
- return config_help("password");
- const std::string hostname = Config::get("hostname", "");
- if (hostname.empty())
- return config_help("hostname");
-
-
-#ifdef USE_DATABASE
- try {
- open_database();
- } catch (const std::exception& e) {
- log_error(e.what());
- return 1;
- }
-#endif
-
// Block the signals we want to manage. They will be unblocked only during
// the epoll_pwait or ppoll calls. This avoids some race conditions,
// explained in man 2 pselect on linux
@@ -126,7 +89,10 @@ int main(int ac, char** av)
sigaction(SIGUSR1, &on_sigusr, nullptr);
sigaction(SIGUSR2, &on_sigusr, nullptr);
sigaction(SIGHUP, &on_sigusr, nullptr);
+}
+static int main_loop(std::string hostname, std::string password)
+{
auto p = std::make_shared<Poller>();
#ifdef UDNS_FOUND
@@ -163,7 +129,7 @@ int main(int ac, char** av)
dns_handler.destroy();
#endif
if (identd)
- identd->shutdown();
+ identd->shutdown();
// Cancel the timer for a potential reconnection
TimedEventsManager::instance().cancel("XMPP reconnection");
}
@@ -206,7 +172,7 @@ int main(int ac, char** av)
dns_handler.destroy();
#endif
if (identd)
- identd->shutdown();
+ identd->shutdown();
}
}
// If the only existing connection is the one to the XMPP component:
@@ -225,3 +191,51 @@ int main(int ac, char** av)
log_info("All connections cleanly closed, have a nice day.");
return 0;
}
+
+int main(int ac, char** av)
+{
+ if (ac > 1)
+ {
+ const std::string arg = av[1];
+ if (arg.size() >= 2 && arg[0] == '-' && arg[1] == '-')
+ {
+ if (arg == "--help")
+ return display_help();
+ else
+ {
+ std::cerr << "Unknow command line option: " << arg
+ << std::endl;
+ return 1;
+ }
+ }
+ }
+ const std::string conf_filename =
+ ac > 1 ? av[1]: xdg_config_path("biboumi.cfg");
+ std::cout << "Using configuration file: " << conf_filename << std::endl;
+
+ if (!Config::read_conf(conf_filename))
+ return config_help("");
+
+ const std::string password = Config::get("password", "");
+ if (password.empty())
+ return config_help("password");
+ const std::string hostname = Config::get("hostname", "");
+ if (hostname.empty())
+ return config_help("hostname");
+
+#ifdef USE_DATABASE
+ try
+ {
+ open_database();
+ }
+ catch (const std::exception& e)
+ {
+ log_error(e.what());
+ return 1;
+ }
+#endif
+
+ setup_signals();
+
+ return main_loop(std::move(hostname), std::move(password));
+}