statustime: Add signal handling.

Because why not? 😊
This commit is contained in:
tastytea 2021-08-14 21:28:06 +02:00
parent 53d7d7b1d8
commit 2f80b3573b
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 22 additions and 0 deletions

View File

@ -4,11 +4,30 @@
#include <fmt/core.h>
#include <chrono>
#include <csignal>
#include <exception>
#include <iostream>
#include <locale>
#include <thread>
void signal_handler(int signum)
{
switch (signum)
{
case SIGTERM:
case SIGINT:
{
std::cout << "\n<span color='red'>Time script terminated.</span>\n";
std::exit(signum); // NOLINT(concurrency-mt-unsafe)
break;
}
default:
{
break;
}
}
}
int main()
{
using fmt::format;
@ -20,6 +39,9 @@ int main()
// Set explicitly, because LC_TIME is en_DK.UTF-8.
std::locale::global(std::locale("de_DE.UTF-8"));
std::signal(SIGINT, signal_handler);
std::signal(SIGTERM, signal_handler);
try
{
while (true)