Commit 3b01d657 authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

Manage SIGTERM, SIGTSTP, SIGCONT signals

parent 800629a7
......@@ -116,7 +116,7 @@ void blc_command_remove(const char *command_name){
}
if (i==-1) EXIT_ON_ERROR("You try to remove a command '%s' that does not exist", command_name);
REMOVE_ITEM(&blc_commands, &blc_commands_nb, i);
REMOVE_ITEM_POSITION(&blc_commands, &blc_commands_nb, i);
}
void blc_command_interpret_string(char const *input_string, size_t size){
......
......@@ -408,10 +408,20 @@ void blc_program_args_display_help()
}
static void on_sigterm(int){
fprintf(stderr, "%s: receiving SIGTERM (kill)\n", blc_program_id);
fprintf(stderr, "%s: receiving SIGTERM\n", blc_program_id);
exit(EXIT_SUCCESS);
}
static void on_sigtstp(int){
fprintf(stderr, "%s: receiving SIGTSTP: pause\n", blc_program_id);
blc_status=BLC_PAUSE;
}
static void on_sigcont(int){
fprintf(stderr, "%s: receiving SIGCONT: continue\n", blc_program_id);
blc_status=BLC_RUN;
}
static void on_sigint(int){
if (blc_status==BLC_QUIT){
fprintf(stderr, "%s: receiving SIGINT (Ctrl+C) in quiting mode. Force to quit.\n", blc_program_id);
......@@ -424,7 +434,7 @@ static void on_sigint(int){
}
static void on_sigsegv(int){
fprintf(stderr, "%s: segmentation fault ( memory access error ! )\n", blc_program_id);
fprintf(stderr, "%s: receiving SIGSEGV segmentation fault ( memory access error )\n", blc_program_id);
exit(EXIT_FAILURE);
}
......@@ -444,6 +454,12 @@ void blc_program_init(int *argc, char ***argv, void (*exit_cb)(void))
action.sa_handler = on_sigterm;
SYSTEM_SUCCESS_CHECK(sigaction(SIGTERM, &action, 0), 0, NULL);
action.sa_handler = on_sigtstp;
SYSTEM_SUCCESS_CHECK(sigaction(SIGTSTP, &action, 0), 0, NULL);
action.sa_handler = on_sigcont;
SYSTEM_SUCCESS_CHECK(sigaction(SIGCONT, &action, 0), 0, NULL);
action.sa_handler = on_sigint;
SYSTEM_SUCCESS_CHECK(sigaction(SIGINT, &action, 0), 0, NULL);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment