Capture SIGINT

This commit is contained in:
Denis 2023-12-13 15:36:22 +01:00
parent b24da5890e
commit 2980769cca
No known key found for this signature in database
GPG key ID: DD9B63F805CF5C03

View file

@ -60,15 +60,24 @@ int main(int argc, char ** argv) {
int dev_out_thread_creation = -1; int dev_out_thread_creation = -1;
int out_message_pipes[2]; int out_message_pipes[2];
pipe(out_message_pipes); const int out_msg_pipe_res = pipe(out_message_pipes);
if (out_msg_pipe_res != 0) {
fprintf(stderr, "Unable to create out_message pipe: %d\n", errno);
exit(EXIT_FAILURE);
}
int in_message_pipes[2]; int in_message_pipes[2];
pipe(in_message_pipes); const int in_msg_pipe_res = pipe(in_message_pipes);
if (in_msg_pipe_res != 0) {
fprintf(stderr, "Unable to create out_message pipe: %d\n", errno);
exit(EXIT_FAILURE);
}
// Create a signal set containing only SIGTERM // Create a signal set containing only SIGTERM
sigset_t mask; sigset_t mask;
sigemptyset(&mask); sigemptyset(&mask);
sigaddset(&mask, SIGTERM); sigaddset(&mask, SIGTERM);
sigaddset(&mask, SIGINT);
// Block SIGTERM for the current thread // Block SIGTERM for the current thread
if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1) { if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1) {
@ -154,10 +163,15 @@ int main(int argc, char ** argv) {
// Check the signal received // Check the signal received
if (si.ssi_signo == SIGTERM) { if (si.ssi_signo == SIGTERM) {
printf("Received SIGTERM -- propagating signal\n"); printf("Received SIGTERM -- propagating signal\n");
dev_in_thread_data.flags |= DEV_IN_FLAG_EXIT; dev_in_thread_data.flags |= DEV_IN_FLAG_EXIT;
dev_out_thread_data.flags |= DEV_OUT_FLAG_EXIT; dev_out_thread_data.flags |= DEV_OUT_FLAG_EXIT;
break; break;
} else if (si.ssi_signo == SIGINT) {
printf("Received SIGINT -- propagating signal\n");
dev_in_thread_data.flags |= DEV_IN_FLAG_EXIT;
dev_out_thread_data.flags |= DEV_OUT_FLAG_EXIT;
break;
} }
} }
} }