mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-25 16:20:35 +08:00
mavlink: use /dev/null as default stdin, stdout and stderr
If 0, 1 and/or 2 file descriptors are not open when mavlink module starts (as might be the case for USB auto-start), use default /dev/null so that these numbers are not used by other other files.
This commit is contained in:
@@ -1859,6 +1859,27 @@ Mavlink::configure_streams_to_default(const char *configure_single_stream)
|
||||
int
|
||||
Mavlink::task_main(int argc, char *argv[])
|
||||
{
|
||||
// If stdin, stdout and/or stderr file descriptors (0, 1, 2)
|
||||
// are not open when mavlink module starts (as might be the case for USB auto-start),
|
||||
// use default /dev/null so that these numbers are not used by other other files.
|
||||
if (fcntl(0, F_GETFD) == -1) {
|
||||
int tmp = open("/dev/null", O_RDONLY);
|
||||
dup2(tmp, 0);
|
||||
close(tmp);
|
||||
}
|
||||
|
||||
if (fcntl(1, F_GETFD) == -1) {
|
||||
int tmp = open("/dev/null", O_WRONLY);
|
||||
dup2(tmp, 1);
|
||||
close(tmp);
|
||||
}
|
||||
|
||||
if (fcntl(2, F_GETFD) == -1) {
|
||||
int tmp = open("/dev/null", O_WRONLY);
|
||||
dup2(tmp, 2);
|
||||
close(tmp);
|
||||
}
|
||||
|
||||
int ch;
|
||||
_baudrate = 57600;
|
||||
_datarate = 0;
|
||||
|
||||
Reference in New Issue
Block a user