AP_HAL_Linux: add ConsoleDevice a handler for TTIN signal

In a case ArduPilot is launched as a background process without
detaching with *nohup* like this ./arduplane -C /dev/ttyAMA0 ConsoleDevice
is created and an attempt to read from it is made. This yields in a stopped
process. This is an endeavour to overcome this problem.
This commit is contained in:
Staroselskii Georgii 2016-07-13 16:56:37 +03:00 committed by Andrew Tridgell
parent 8d2b587f71
commit 4ca1b58408
2 changed files with 18 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <AP_HAL/AP_HAL.h>
@ -31,9 +32,24 @@ bool ConsoleDevice::open()
_closed = false;
if (!_set_signal_handlers()) {
close();
return false;
}
return true;
}
bool ConsoleDevice::_set_signal_handlers(void) const
{
struct sigaction sa;
sigemptyset(&sa.sa_mask);
sa.sa_handler = SIG_IGN;
return (sigaction(SIGTTIN, &sa, nullptr) == 0);
}
ssize_t ConsoleDevice::read(uint8_t *buf, uint16_t n)
{
if (_closed) {

View File

@ -19,4 +19,6 @@ private:
int _rd_fd = -1;
int _wr_fd = -1;
bool _closed = true;
bool _set_signal_handlers(void) const;
};