diff options
Diffstat (limited to 'server/src/main.cpp')
-rw-r--r-- | server/src/main.cpp | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/server/src/main.cpp b/server/src/main.cpp index 09b0b62..214b6b5 100644 --- a/server/src/main.cpp +++ b/server/src/main.cpp @@ -52,15 +52,42 @@ server *serv = nullptr; //TODO: "core" config section architecture, define base settings -void sigint_handler(int sig) +void on_exit() { + serv->terminate(); bpt::write_info(runtime_config.config_file_path, runtime_config.config_file); //save config on sigint - exit(0); + for(auto m : modules->get_downloader_modules()) + delete m; + for(auto m : modules->get_metadata_modules()) + delete m; +} + +void sig_handler(int sig) +{ + switch(sig) + { + default: + { + on_exit(); + exit(0); + } + break; + } } extern "C" int main(int argc, char *argv[]) { - signal(SIGINT, sigint_handler); + //handle signals + signal(SIGINT, sig_handler); + signal(SIGTERM, sig_handler); + signal(SIGABRT, sig_handler); + + //this will not work + signal(SIGKILL, sig_handler); + signal(SIGSTOP, sig_handler); + + + bpo::options_description desc("Available commands and options"); desc.add_options() ("help,h", "this message") |