From cf618d55723e645cfe7865b8a55ec718b1ddd2bb Mon Sep 17 00:00:00 2001 From: Ailin Nemui Date: Tue, 13 Mar 2018 11:25:50 +0100 Subject: optional identd --- src/main.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index c877e43..c2b5431 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -135,7 +135,9 @@ int main(int ac, char** av) std::make_shared(p, hostname, password); xmpp_component->start(); - IdentdServer identd(*xmpp_component, p, static_cast(Config::get_int("identd_port", 113))); + std::unique_ptr identd; + if (Config::get_int("identd_port", 113) != 0) + identd = std::make_unique(*xmpp_component, p, static_cast(Config::get_int("identd_port", 113))); auto timeout = TimedEventsManager::instance().get_timeout(); while (p->poll(timeout) != -1) @@ -144,7 +146,7 @@ int main(int ac, char** av) // Check for empty irc_clients (not connected, or with no joined // channel) and remove them xmpp_component->clean(); - identd.clean(); + if (identd) identd->clean(); if (stop) { log_info("Signal received, exiting..."); @@ -157,7 +159,7 @@ int main(int ac, char** av) #ifdef UDNS_FOUND dns_handler.destroy(); #endif - identd.shutdown(); + if (identd) identd->shutdown(); // Cancel the timer for a potential reconnection TimedEventsManager::instance().cancel("XMPP reconnection"); } @@ -199,7 +201,7 @@ int main(int ac, char** av) #ifdef UDNS_FOUND dns_handler.destroy(); #endif - identd.shutdown(); + if (identd) identd->shutdown(); } } // If the only existing connection is the one to the XMPP component: -- cgit v1.2.3 From 5ea51fea1b4efadbf3d3ec26dbef930280e7275c Mon Sep 17 00:00:00 2001 From: Ailin Nemui Date: Thu, 15 Mar 2018 10:18:15 +0100 Subject: follow coding style --- src/main.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index c2b5431..59fda4e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -146,7 +146,8 @@ int main(int ac, char** av) // Check for empty irc_clients (not connected, or with no joined // channel) and remove them xmpp_component->clean(); - if (identd) identd->clean(); + if (identd) + identd->clean(); if (stop) { log_info("Signal received, exiting..."); @@ -159,7 +160,8 @@ int main(int ac, char** av) #ifdef UDNS_FOUND dns_handler.destroy(); #endif - if (identd) identd->shutdown(); + if (identd) + identd->shutdown(); // Cancel the timer for a potential reconnection TimedEventsManager::instance().cancel("XMPP reconnection"); } @@ -201,7 +203,8 @@ int main(int ac, char** av) #ifdef UDNS_FOUND dns_handler.destroy(); #endif - if (identd) identd->shutdown(); + if (identd) + identd->shutdown(); } } // If the only existing connection is the one to the XMPP component: -- cgit v1.2.3 From ed36c26598892c60c6d2c9a096f536cc1f4705cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 6 May 2018 12:11:51 +0200 Subject: Also handle SIGHUP to reload the configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because that’s what is typically done on other deamons, and we don’t want to suprise users. --- src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 59fda4e..09adc5c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -103,6 +103,7 @@ int main(int ac, char** av) sigaddset(&mask, SIGTERM); sigaddset(&mask, SIGUSR1); sigaddset(&mask, SIGUSR2); + sigaddset(&mask, SIGHUP); sigprocmask(SIG_BLOCK, &mask, nullptr); // Install the signals used to exit the process cleanly, or reload the @@ -124,6 +125,7 @@ int main(int ac, char** av) on_sigusr.sa_flags = 0; sigaction(SIGUSR1, &on_sigusr, nullptr); sigaction(SIGUSR2, &on_sigusr, nullptr); + sigaction(SIGHUP, &on_sigusr, nullptr); auto p = std::make_shared(); -- cgit v1.2.3 From 9fa7591058f8e4b32f64a2b61fe85c277cf2a9d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Mon, 6 Aug 2018 21:14:05 +0200 Subject: Split the main() into smaller functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit That’s not really enough, but better --- src/main.cpp | 94 ++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 54 insertions(+), 40 deletions(-) (limited to 'src/main.cpp') 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(); #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)); +} -- cgit v1.2.3 From b1564e4ddc3e54ad78788a6f5643056d03a41678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 23 Aug 2018 20:31:31 +0200 Subject: Fix a bunch of int to unsigned int conversion warnings --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 04500b7..2448197 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -77,7 +77,7 @@ static void setup_signals() sigfillset(&on_sigint.sa_mask); // we want to catch that signal only once. // Sending SIGINT again will "force" an exit - on_sigint.sa_flags = SA_RESETHAND; + on_sigint.sa_flags = 0 & SA_RESETHAND; sigaction(SIGINT, &on_sigint, nullptr); sigaction(SIGTERM, &on_sigint, nullptr); -- cgit v1.2.3