Catching SIGTERM, cosmetic changes

This commit is contained in:
tastytea 2018-05-12 10:42:22 +02:00
parent 18b92496e5
commit ca261ca031
Signed by: tastytea
GPG Key ID: 59346E0EA35C67E5
4 changed files with 9 additions and 10 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7) cmake_minimum_required (VERSION 3.7)
project (expandurl-mastodon project (expandurl-mastodon
VERSION 0.2.0 VERSION 0.2.1
LANGUAGES CXX LANGUAGES CXX
) )

View File

@ -67,7 +67,7 @@ public:
/*! /*!
* @brief Starts listening on Mastodon * @brief Starts listening on Mastodon
*/ */
const bool start(); const void start();
/*! /*!
* @brief Stops listening on Mastodon * @brief Stops listening on Mastodon
*/ */

View File

@ -33,6 +33,7 @@ void signal_handler(int signum)
switch (signum) switch (signum)
{ {
case SIGINT: case SIGINT:
case SIGTERM:
if (!running) if (!running)
{ {
cout << "Forced close.\n"; cout << "Forced close.\n";
@ -66,6 +67,7 @@ const std::vector<string> get_urls(const string &html)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
signal(SIGINT, signal_handler); signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
curlpp::initialize(); curlpp::initialize();
Listener listener; Listener listener;
@ -124,8 +126,8 @@ int main(int argc, char *argv[])
} }
} }
} }
listener.stop();
listener.stop();
curlpp::Cleanup(); curlpp::Cleanup();
return 0; return 0;

View File

@ -29,10 +29,6 @@ Listener::Listener()
, _stream("") , _stream("")
, _ptr(nullptr) , _ptr(nullptr)
, _running(false) , _running(false)
{
}
const bool Listener::start()
{ {
const string filepath = static_cast<const string>(getenv("HOME")) + const string filepath = static_cast<const string>(getenv("HOME")) +
"/.config/expandurl-mastodon.cfg"; "/.config/expandurl-mastodon.cfg";
@ -52,9 +48,12 @@ const bool Listener::start()
else else
{ {
cerr << "ERROR: Could not open " << filepath << '\n'; cerr << "ERROR: Could not open " << filepath << '\n';
return false; exit(1);
} }
}
const void Listener::start()
{
_thread = std::thread([=] _thread = std::thread([=]
{ {
_running = true; _running = true;
@ -65,8 +64,6 @@ const bool Listener::start()
cerr << "DEBUG: Connection lost.\n"; cerr << "DEBUG: Connection lost.\n";
_running = false; _running = false;
}); });
return true;
} }
const void Listener::stop() const void Listener::stop()