Skip to content
Snippets Groups Projects
Commit fe8fd924 authored by vertuozzo's avatar vertuozzo
Browse files

Correct stop of a node via a KILL (SIGINT, SIGTERM, etc) signal

parent 6d9fa3f9
No related branches found
No related tags found
3 merge requests!39bugs-4815,!38feature-4803,!37Correct stop of a node via a KILL (SIGINT, SIGTERM, etc) signal
Pipeline #7578 passed with stages
in 1 minute and 59 seconds
......@@ -493,9 +493,9 @@ int main( int argc, const char **argv )
//failure:
#ifdef DAP_SUPPORT_PYTHON_PLUGINS
dap_chain_plugins_deinit();
#endif
// #ifdef DAP_SUPPORT_PYTHON_PLUGINS
// dap_chain_plugins_deinit();
// #endif
dap_dns_server_stop();
dap_stream_deinit();
dap_stream_ctl_deinit();
......
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "dap_common.h"
#include "dap_file_utils.h"
#include "dap_events.h"
#include "dap_chain_global_db.h"
#include "sig_unix_handler.h"
#define LOG_TAG "sig_unix_handler"
static const char *l_pid_path;
static const char *s_pid_path = NULL;
static void clear_pid_file() {
FILE * f = fopen(l_pid_path, "w");
FILE * f = fopen(s_pid_path, "w");
if (f == NULL)
log_it(L_WARNING, "Pid file not cleared");
else
fclose(f);
}
_Noreturn static void sig_exit_handler(int sig_code) {
static void sig_exit_handler(int sig_code) {
log_it(L_DEBUG, "Got exit code: %d", sig_code);
clear_pid_file();
//#ifdef DAP_SUPPORT_PYTHON_PLUGINS
// dap_chain_plugins_deinit();
//#endif
dap_chain_node_mempool_autoproc_deinit();
dap_chain_net_srv_xchange_deinit();
dap_chain_net_srv_stake_deinit();
dap_chain_net_deinit();
dap_chain_global_db_deinit();
dap_chain_deinit();
dap_stream_ctl_deinit();
dap_stream_deinit();
dap_enc_ks_deinit();
enc_http_deinit();
dap_http_deinit();
dap_dns_server_stop();
dap_server_deinit();
dap_events_stop_all();
dap_events_deinit();
dap_config_close( g_config );
dap_common_deinit();
//log_it(L_NOTICE,"Stopped Cellframe Node");
//fflush(stdout);
exit(0);
}
/**
* @brief sig_unix_handler_init
* @param a_pid_path
* @return
*/
int sig_unix_handler_init(const char *a_pid_path)
int sig_unix_handler_init(const char *a_pid_path)
{
char * l_pid_dir = dap_path_get_dirname(a_pid_path);
sleep(1);
dap_mkdir_with_parents(l_pid_dir);
DAP_DELETE(l_pid_dir);
//char * l_pid_dir = dap_path_get_dirname(a_pid_path);
//sleep(1); // Don't know why but without it it crashes O_o
//dap_mkdir_with_parents(l_pid_dir);
//DAP_DELETE(l_pid_dir);
//log_it(L_DEBUG, "Init");
s_pid_path = strdup(a_pid_path);
l_pid_path = strdup(a_pid_path);
signal(SIGINT, sig_exit_handler);
signal(SIGTERM, sig_exit_handler);
signal(SIGHUP, sig_exit_handler);
signal(SIGTERM, sig_exit_handler);
signal(SIGQUIT, sig_exit_handler);
signal(SIGTSTP, sig_exit_handler);
return 0;
}
int sig_unix_handler_deinit() {
free((char*)l_pid_path);
//log_it(L_DEBUG, "Deinit");
if( s_pid_path )
DAP_DELETE(s_pid_path);
signal(SIGTERM, SIG_DFL);
signal(SIGINT, SIG_DFL);
signal(SIGHUP, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
signal(SIGTSTP, SIG_DFL);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment