From e5ed05766dfb8bb0a6160018e6b3f32e18ad0d38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Mon, 13 Aug 2018 13:18:08 +0200 Subject: [PATCH] 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 --- platforms/posix/src/px4_daemon/server.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/platforms/posix/src/px4_daemon/server.cpp b/platforms/posix/src/px4_daemon/server.cpp index c61bc72eaa..8963bebc7a 100644 --- a/platforms/posix/src/px4_daemon/server.cpp +++ b/platforms/posix/src/px4_daemon/server.cpp @@ -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) {