diff --git a/src/main.cc b/src/main.cc index 25c17a9..48f72be 100644 --- a/src/main.cc +++ b/src/main.cc @@ -195,6 +195,11 @@ void startUsingCommandline(Configuration *config) command = prefix+"rtl_sdr -f "+freq+" -s 16000000 - 2>/dev/null | "+prefix+"rtl_wmbus"; } verbose("(rtlwmbus) using command: %s\n", command.c_str()); + onChild([command,&manager](){ + warning("(rtlwmbus) child process exited! Command was: \"%s\"\n", command.c_str()); + manager.get()->stop(); + }); + wmbus = openRTLWMBUS(command, manager.get()); break; } diff --git a/src/util.cc b/src/util.cc index a782596..f9e57c8 100644 --- a/src/util.cc +++ b/src/util.cc @@ -39,9 +39,21 @@ void exitHandler(int signum) if (exit_handler) exit_handler(); } +function child_handler; + +void childProcessDied(int signum) +{ + if (child_handler) child_handler(); +} + void doNothing(int signum) { } +void onChild(function cb) +{ + child_handler = cb; +} + void onExit(function cb) { exit_handler = cb; @@ -58,6 +70,10 @@ void onExit(function cb) sigaction (SIGTERM, NULL, &old_action); if (old_action.sa_handler != SIG_IGN) sigaction (SIGTERM, &new_action, NULL); + new_action.sa_handler = childProcessDied; + sigaction (SIGCHLD, NULL, &old_action); + if (old_action.sa_handler != SIG_IGN) sigaction (SIGCHLD, &new_action, NULL); + new_action.sa_handler = doNothing; sigemptyset (&new_action.sa_mask); new_action.sa_flags = 0; diff --git a/src/util.h b/src/util.h index c5f43bd..3844e64 100644 --- a/src/util.h +++ b/src/util.h @@ -25,6 +25,7 @@ #include void onExit(std::function cb); +void onChild(std::function cb); typedef unsigned char uchar;