Added early exit if rtlwmbus child process terminates.

pull/22/head
weetmuts 2019-04-02 19:23:21 +02:00
rodzic 2b13e884b7
commit 6fc79697c3
3 zmienionych plików z 22 dodań i 0 usunięć

Wyświetl plik

@ -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;
}

Wyświetl plik

@ -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;

Wyświetl plik

@ -25,6 +25,7 @@
#include<vector>
void onExit(std::function<void()> cb);
void onChild(std::function<void()> cb);
typedef unsigned char uchar;