mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2025-09-23 03:52:35 -04:00
Merge pull request #488 from kiwix/kiwix-serve_sigterm_handling
This commit is contained in:
commit
7659efa97c
@ -27,6 +27,7 @@
|
|||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
#else
|
#else
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
|
# include <signal.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
@ -97,8 +98,40 @@ string loadCustomTemplate (string customIndexPath) {
|
|||||||
return indexTemplateString;
|
return indexTemplateString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
volatile sig_atomic_t waiting = false;
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
void handle_sigterm(int signum)
|
||||||
|
{
|
||||||
|
if ( waiting == false ) {
|
||||||
|
_exit(signum);
|
||||||
|
}
|
||||||
|
waiting = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef void (*SignalHandler)(int);
|
||||||
|
|
||||||
|
void set_signal_handler(int sig, SignalHandler handler)
|
||||||
|
{
|
||||||
|
struct sigaction sa;
|
||||||
|
sigaction(sig, NULL, &sa);
|
||||||
|
sa.sa_handler = handler;
|
||||||
|
sigaction(sig, &sa, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup_sighandlers()
|
||||||
|
{
|
||||||
|
set_signal_handler(SIGTERM, &handle_sigterm);
|
||||||
|
set_signal_handler(SIGINT, &handle_sigterm);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
|
setup_sighandlers();
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string rootLocation = "";
|
std::string rootLocation = "";
|
||||||
kiwix::Library library;
|
kiwix::Library library;
|
||||||
unsigned int nb_threads = DEFAULT_THREADS;
|
unsigned int nb_threads = DEFAULT_THREADS;
|
||||||
@ -298,7 +331,7 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Run endless (until PPID dies) */
|
/* Run endless (until PPID dies) */
|
||||||
bool waiting = true;
|
waiting = true;
|
||||||
do {
|
do {
|
||||||
if (PPID > 0) {
|
if (PPID > 0) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
Loading…
x
Reference in New Issue
Block a user