mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-30 16:46:09 +08:00
Merge pull request #17065 from PX4/pr/fix-mavlink-shell
MAVLink shell: Ensure that nothing is written to the file handles during shell creation.
This commit is contained in:
@@ -37,7 +37,7 @@ px4_add_board(
|
|||||||
imu/invensense/icm20649
|
imu/invensense/icm20649
|
||||||
imu/invensense/icm20689
|
imu/invensense/icm20689
|
||||||
irlock
|
irlock
|
||||||
lights/blinkm
|
#lights/blinkm
|
||||||
lights/rgbled
|
lights/rgbled
|
||||||
lights/rgbled_ncp5623c
|
lights/rgbled_ncp5623c
|
||||||
lights/rgbled_pwm
|
lights/rgbled_pwm
|
||||||
|
|||||||
@@ -84,8 +84,6 @@ int MavlinkShell::start()
|
|||||||
* keeps (duplicates) the first 3 fd's when creating a new task, all others are not inherited.
|
* keeps (duplicates) the first 3 fd's when creating a new task, all others are not inherited.
|
||||||
* This means we need to temporarily change the first 3 fd's of the current task (or at least
|
* This means we need to temporarily change the first 3 fd's of the current task (or at least
|
||||||
* the first 2 if stdout=stderr).
|
* the first 2 if stdout=stderr).
|
||||||
* And we hope :-) that during the temporary phase, no other thread from the same task writes to
|
|
||||||
* stdout (as it would end up in the pipe).
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (pipe(p1) != 0) {
|
if (pipe(p1) != 0) {
|
||||||
@@ -105,6 +103,16 @@ int MavlinkShell::start()
|
|||||||
_shell_fds[0] = p2[0];
|
_shell_fds[0] = p2[0];
|
||||||
_shell_fds[1] = p1[1];
|
_shell_fds[1] = p1[1];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Ensure that during the temporary phase no other thread from the same task writes to
|
||||||
|
* stdout (as it would end up in the pipe).
|
||||||
|
*/
|
||||||
|
#ifdef __PX4_NUTTX
|
||||||
|
sched_lock();
|
||||||
|
#endif /* __PX4_NUTTX */
|
||||||
|
fflush(stdout);
|
||||||
|
fflush(stderr);
|
||||||
|
|
||||||
int fd_backups[2]; //we don't touch stderr, we will redirect it to stdout in the startup of the shell task
|
int fd_backups[2]; //we don't touch stderr, we will redirect it to stdout in the startup of the shell task
|
||||||
|
|
||||||
for (int i = 0; i < 2; ++i) {
|
for (int i = 0; i < 2; ++i) {
|
||||||
@@ -140,6 +148,10 @@ int MavlinkShell::start()
|
|||||||
close(fd_backups[i]);
|
close(fd_backups[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __PX4_NUTTX
|
||||||
|
sched_unlock();
|
||||||
|
#endif /* __PX4_NUTTX */
|
||||||
|
|
||||||
//close unused pipe fd's
|
//close unused pipe fd's
|
||||||
close(_shell_fds[0]);
|
close(_shell_fds[0]);
|
||||||
close(_shell_fds[1]);
|
close(_shell_fds[1]);
|
||||||
|
|||||||
Reference in New Issue
Block a user