mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-22 01:12:31 +00:00
px4_daemon server: fix startup race condition
The FIFO was created in the server thread, and the PX4 main thread could already have continued and started to execute the bash script. In that case the client tried to open the FIFO but it did not exist yet. Client error: ERROR [px4_daemon] pipe open fail ERROR [px4_daemon] Could not send commands
This commit is contained in:
@@ -72,6 +72,15 @@ Server::~Server()
|
||||
int
|
||||
Server::start()
|
||||
{
|
||||
std::string client_send_pipe_path = get_client_send_pipe_path(_instance_id);
|
||||
|
||||
// Delete pipe in case it exists already.
|
||||
unlink(client_send_pipe_path.c_str());
|
||||
|
||||
// Create new pipe to listen to clients.
|
||||
// This needs to happen before we return from this method, so that the caller can launch clients.
|
||||
mkfifo(client_send_pipe_path.c_str(), 0666);
|
||||
|
||||
if (0 != pthread_create(&_server_main_pthread,
|
||||
nullptr,
|
||||
_server_main_trampoline,
|
||||
@@ -112,12 +121,6 @@ Server::_server_main(void *arg)
|
||||
}
|
||||
|
||||
std::string client_send_pipe_path = get_client_send_pipe_path(_instance_id);
|
||||
|
||||
// Delete pipe in case it exists already.
|
||||
unlink(client_send_pipe_path.c_str());
|
||||
|
||||
// Create new pipe to listen to clients.
|
||||
mkfifo(client_send_pipe_path.c_str(), 0666);
|
||||
int client_send_pipe_fd = open(client_send_pipe_path.c_str(), O_RDONLY);
|
||||
|
||||
while (true) {
|
||||
|
||||
Reference in New Issue
Block a user