Handle SIGTERM as well (in addition to SIGINT) when saving changes

* e.g. ffmpeg handles SIGTERM as well to finalize writing the file
* not tested yet
This commit is contained in:
Martchus 2020-06-02 17:16:38 +02:00
parent fd18fa2bff
commit bb4bb29ab9
1 changed files with 4 additions and 3 deletions

View File

@ -40,7 +40,7 @@ std::function<void()> InterruptHandler::s_handler;
bool InterruptHandler::s_handlerRegistered = false;
/*!
* \brief Registers the specified \a handler for SIGINT as long as this object is alive.
* \brief Registers the specified \a handler for SIGINT and SIGTERM as long as this object is alive.
* \remarks The specified \a handler should only call functions which are permitted to be used in signal handlers
* (eg. use POSIX write() instread of std::cout).
* \throws Throws std::runtime_error when attempting to create a 2nd instance.
@ -57,6 +57,7 @@ InterruptHandler::InterruptHandler(std::function<void()> handler)
if (!s_handlerRegistered) {
s_handlerRegistered = true;
signal(SIGINT, &InterruptHandler::handler);
signal(SIGTERM, &InterruptHandler::handler);
}
}
@ -84,9 +85,9 @@ void InterruptHandler::handler(int signum)
write(STDOUT_FILENO, "\n", 1);
}
if (EscapeCodes::enabled) {
write(STDOUT_FILENO, "\e[1;33mWarning:\e[0m \e[1mInterrupt received, trying to abort ongoing process ...\e[0m\n", 84);
write(STDOUT_FILENO, "\e[1;33mWarning:\e[0m \e[1mSignal received, trying to abort ongoing process ...\e[0m\n", 84);
} else {
write(STDOUT_FILENO, "Warning: Interrupt received, trying to abort ongoing process ...\n", 65);
write(STDOUT_FILENO, "Warning: Signal received, trying to abort ongoing process ...\n", 65);
}
// call custom handler