|
|
|
@ -722,6 +722,8 @@ int init_blockchain_file() |
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define array_len(a) ( sizeof(a) / sizeof(a[0]) )
|
|
|
|
|
|
|
|
int main(int ac, char** av)
|
|
|
|
{
|
|
|
|
btc_node_group* group = NULL;
|
|
|
|
@ -729,6 +731,11 @@ int main(int ac, char** av) |
|
|
|
cb_file_write_log_flag = false;
|
|
|
|
cb_file_write_log_filter = "STATUS";
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if parameter, change dir to this param
|
|
|
|
*/
|
|
|
|
if (ac > 1) chdir(av[1]);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Daemonize
|
|
|
|
*/
|
|
|
|
@ -737,47 +744,33 @@ int main(int ac, char** av) |
|
|
|
/*
|
|
|
|
* Trapper les signaux pour fermer correctement le programme
|
|
|
|
*/
|
|
|
|
if (signal(SIGCHLD,SIG_IGN) == SIG_ERR)
|
|
|
|
{
|
|
|
|
printf("\ncan't catch SIGCHLD\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (signal(SIGTSTP,SIG_IGN) == SIG_ERR)
|
|
|
|
{
|
|
|
|
printf("\ncan't catch SIGTSTP\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (signal(SIGTTOU,SIG_IGN) == SIG_ERR)
|
|
|
|
{
|
|
|
|
printf("\ncan't catch SIGTTOU\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (signal(SIGTTIN,SIG_IGN) == SIG_ERR)
|
|
|
|
{
|
|
|
|
printf("\ncan't catch SIGTTIN\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
int les_signaux_ign[] = { SIGCHLD, SIGTSTP, SIGTTOU, SIGTTIN };
|
|
|
|
int les_signaux[] = { SIGHUP, SIGTERM, SIGINT };
|
|
|
|
size_t n;
|
|
|
|
|
|
|
|
if (signal(SIGHUP,signal_handler) == SIG_ERR)
|
|
|
|
{
|
|
|
|
printf("\ncan't catch SIGHUP\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (signal(SIGTERM,signal_handler) == SIG_ERR)
|
|
|
|
n = array_len(les_signaux_ign);
|
|
|
|
for(int i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
printf("\ncan't catch SIGTERM\n");
|
|
|
|
return 1;
|
|
|
|
if (signal(les_signaux_ign[i],SIG_IGN) == SIG_ERR)
|
|
|
|
{
|
|
|
|
printf("\ncan't catch signal %d\n", les_signaux_ign[i]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (signal(SIGINT, signal_handler) == SIG_ERR)
|
|
|
|
|
|
|
|
n = array_len(les_signaux);
|
|
|
|
for(int i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
printf("\ncan't catch SIGINT\n");
|
|
|
|
return 1;
|
|
|
|
if (signal(les_signaux[i],signal_handler) == SIG_ERR)
|
|
|
|
{
|
|
|
|
printf("\ncan't catch signal %d\n", les_signaux[i]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Gestion du fichier de chaine de blocks
|
|
|
|
*/
|
|
|
|
if (ac > 1) simple_db_path = av[1];
|
|
|
|
if (0 != init_blockchain_file()) return 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
|