Skip to content
Snippets Groups Projects
Commit e5ed0576 authored by Beat Küng's avatar Beat Küng
Browse files

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
parent 52168f96
No related branches found
No related tags found
No related merge requests found
......@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment