Handle signals from ddcd.
This commit is contained in:
parent
c6e0a8f5c8
commit
2a6b1c2073
2 changed files with 23 additions and 1 deletions
19
ddcd.cpp
19
ddcd.cpp
|
@ -64,6 +64,15 @@ int proc_exists(pid_t pid)
|
||||||
return kill(pid, 0) != -1;
|
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;
|
client_t* this_client;
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
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");
|
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;
|
struct sockaddr_in addr_host;
|
||||||
int listen_socket;
|
int listen_socket;
|
||||||
std::vector<client_t*> clients;
|
std::vector<client_t*> clients;
|
||||||
|
@ -202,6 +220,7 @@ int main(int argc, char* argv[])
|
||||||
break;
|
break;
|
||||||
case M_FASTDDC:
|
case M_FASTDDC:
|
||||||
sprintf(main_subprocess_cmd_buf, subprocess_args_fastddc_1, decimation, transition_bw);
|
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
|
close(STDIN_FILENO); // redirect stdin to the stdin of the subprocess
|
||||||
main_subprocess_pid = run_subprocess( main_subprocess_cmd_buf, 0, pipe_s2m );
|
main_subprocess_pid = run_subprocess( main_subprocess_cmd_buf, 0, pipe_s2m );
|
||||||
break;
|
break;
|
||||||
|
|
5
ddcd.h
5
ddcd.h
|
@ -15,6 +15,7 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
#include <sys/prctl.h>
|
||||||
|
|
||||||
typedef struct client_s
|
typedef struct client_s
|
||||||
{
|
{
|
||||||
|
@ -34,6 +35,7 @@ void print_client(client_t* client, const char* what);
|
||||||
int proc_exists(pid_t pid);
|
int proc_exists(pid_t pid);
|
||||||
pid_t run_subprocess(char* cmd, int* pipe_in, int* pipe_out);
|
pid_t run_subprocess(char* cmd, int* pipe_in, int* pipe_out);
|
||||||
void maxfd(int* maxfd, int fd);
|
void maxfd(int* maxfd, int fd);
|
||||||
|
void sig_handler(int signo);
|
||||||
|
|
||||||
typedef enum ddc_method_e
|
typedef enum ddc_method_e
|
||||||
{
|
{
|
||||||
|
@ -49,5 +51,6 @@ const char subprocess_cmd_td[] = "csdr "
|
||||||
#endif
|
#endif
|
||||||
" --pipe %d,%d | csdr fir_decimate_cc %d %g";
|
" --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";
|
const char subprocess_args_fastddc_2[] = "csdr fastddc_inv_cc %d --pipe %d,%d %g";
|
||||||
|
|
Loading…
Reference in a new issue