mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 06:28:27 -04:00
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:
parent
8d2b587f71
commit
4ca1b58408
@ -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) {
|
||||
|
@ -19,4 +19,6 @@ private:
|
||||
int _rd_fd = -1;
|
||||
int _wr_fd = -1;
|
||||
bool _closed = true;
|
||||
|
||||
bool _set_signal_handlers(void) const;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user