From 2a6b1c2073379e2b7581afd40c9608b8dffcdf63 Mon Sep 17 00:00:00 2001 From: ha7ilm Date: Wed, 2 Dec 2015 19:38:17 +0100 Subject: [PATCH] Handle signals from ddcd. --- ddcd.cpp | 19 +++++++++++++++++++ ddcd.h | 5 ++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ddcd.cpp b/ddcd.cpp index 968941f..4a9ad88 100644 --- a/ddcd.cpp +++ b/ddcd.cpp @@ -64,6 +64,15 @@ int proc_exists(pid_t pid) return kill(pid, 0) != -1; } +void sig_handler(int signo) +{ + if(pgrp!=1 && pgrp!=0) //I just want to make sure that we cannot kill init or sched + killpg(pgrp, signo); + fprintf(stderr, MSG_START "signal caught, exiting ddcd...\n"); + fflush(stderr); + exit(0); +} + client_t* this_client; int main(int argc, char* argv[]) @@ -131,6 +140,15 @@ int main(int argc, char* argv[]) } else print_exit(MSG_START "invalid parameter given to --method.\n"); + //set signals + struct sigaction sa; + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = sig_handler; + sigaction(SIGKILL, &sa, NULL); + sigaction(SIGQUIT, &sa, NULL); + sigaction(SIGHUP, &sa, NULL); + prctl(PR_SET_PDEATHSIG, SIGHUP); //get a signal when parent exits + struct sockaddr_in addr_host; int listen_socket; std::vector clients; @@ -202,6 +220,7 @@ int main(int argc, char* argv[]) break; case M_FASTDDC: sprintf(main_subprocess_cmd_buf, subprocess_args_fastddc_1, decimation, transition_bw); + fprintf(stderr, MSG_START "starting main_subprocess_cmd: %s\n", main_subprocess_cmd_buf); close(STDIN_FILENO); // redirect stdin to the stdin of the subprocess main_subprocess_pid = run_subprocess( main_subprocess_cmd_buf, 0, pipe_s2m ); break; diff --git a/ddcd.h b/ddcd.h index 5bdd085..4d6bb33 100644 --- a/ddcd.h +++ b/ddcd.h @@ -15,6 +15,7 @@ #include #include #include +#include typedef struct client_s { @@ -34,6 +35,7 @@ void print_client(client_t* client, const char* what); int proc_exists(pid_t pid); pid_t run_subprocess(char* cmd, int* pipe_in, int* pipe_out); void maxfd(int* maxfd, int fd); +void sig_handler(int signo); typedef enum ddc_method_e { @@ -49,5 +51,6 @@ const char subprocess_cmd_td[] = "csdr " #endif " --pipe %d,%d | csdr fir_decimate_cc %d %g"; -const char subprocess_args_fastddc_1[] = "csdr fastddc_fwd_cc %d %g"; +const char subprocess_args_fastddc_1[] = "csdr through %d %g"; +//const char subprocess_args_fastddc_1[] = "csdr fastddc_fwd_cc %d %g"; const char subprocess_args_fastddc_2[] = "csdr fastddc_inv_cc %d --pipe %d,%d %g";