From ca261ca031fdceaf53a1849d06e906c5fa1ae28e Mon Sep 17 00:00:00 2001 From: tastytea Date: Sat, 12 May 2018 10:42:22 +0200 Subject: [PATCH] Catching SIGTERM, cosmetic changes --- CMakeLists.txt | 2 +- src/expandurl-mastodon.hpp | 2 +- src/main.cpp | 4 +++- src/masto.cpp | 11 ++++------- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 207ba15..5183206 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project (expandurl-mastodon - VERSION 0.2.0 + VERSION 0.2.1 LANGUAGES CXX ) diff --git a/src/expandurl-mastodon.hpp b/src/expandurl-mastodon.hpp index 7d2ec87..d3bf7a7 100644 --- a/src/expandurl-mastodon.hpp +++ b/src/expandurl-mastodon.hpp @@ -67,7 +67,7 @@ public: /*! * @brief Starts listening on Mastodon */ - const bool start(); + const void start(); /*! * @brief Stops listening on Mastodon */ diff --git a/src/main.cpp b/src/main.cpp index b4b9f8a..fa2ac90 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,6 +33,7 @@ void signal_handler(int signum) switch (signum) { case SIGINT: + case SIGTERM: if (!running) { cout << "Forced close.\n"; @@ -66,6 +67,7 @@ const std::vector get_urls(const string &html) int main(int argc, char *argv[]) { signal(SIGINT, signal_handler); + signal(SIGTERM, signal_handler); curlpp::initialize(); Listener listener; @@ -124,8 +126,8 @@ int main(int argc, char *argv[]) } } } - listener.stop(); + listener.stop(); curlpp::Cleanup(); return 0; diff --git a/src/masto.cpp b/src/masto.cpp index 13aee61..cd63b8e 100644 --- a/src/masto.cpp +++ b/src/masto.cpp @@ -29,10 +29,6 @@ Listener::Listener() , _stream("") , _ptr(nullptr) , _running(false) -{ -} - -const bool Listener::start() { const string filepath = static_cast(getenv("HOME")) + "/.config/expandurl-mastodon.cfg"; @@ -52,9 +48,12 @@ const bool Listener::start() else { cerr << "ERROR: Could not open " << filepath << '\n'; - return false; + exit(1); } +} +const void Listener::start() +{ _thread = std::thread([=] { _running = true; @@ -65,8 +64,6 @@ const bool Listener::start() cerr << "DEBUG: Connection lost.\n"; _running = false; }); - - return true; } const void Listener::stop()