kopia lustrzana https://github.com/weetmuts/wmbusmeters
Added early exit if rtlwmbus child process terminates.
rodzic
2b13e884b7
commit
6fc79697c3
|
@ -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;
|
||||
}
|
||||
|
|
16
src/util.cc
16
src/util.cc
|
@ -39,9 +39,21 @@ void exitHandler(int signum)
|
|||
if (exit_handler) exit_handler();
|
||||
}
|
||||
|
||||
function<void()> child_handler;
|
||||
|
||||
void childProcessDied(int signum)
|
||||
{
|
||||
if (child_handler) child_handler();
|
||||
}
|
||||
|
||||
void doNothing(int signum) {
|
||||
}
|
||||
|
||||
void onChild(function<void()> cb)
|
||||
{
|
||||
child_handler = cb;
|
||||
}
|
||||
|
||||
void onExit(function<void()> cb)
|
||||
{
|
||||
exit_handler = cb;
|
||||
|
@ -58,6 +70,10 @@ void onExit(function<void()> 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;
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include<vector>
|
||||
|
||||
void onExit(std::function<void()> cb);
|
||||
void onChild(std::function<void()> cb);
|
||||
|
||||
typedef unsigned char uchar;
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue