fix(posix): initialize PX4 before starting the daemon server

The daemon server's client-handler thread spawns module tasks (e.g. dataman).
Start px4::init_once()/init() before creating px4_daemon::Server so platform init
- uORB, work queues, logging - completes with a happens-before edge to those
tasks. Otherwise a module task racing the still-running init reads globals like
uORB::Manager's instance pointer or the log message advertisement without
synchronization (ThreadSanitizer flags it) - and an atomic would not make it
correct, since the publication could simply be skipped.
This commit is contained in:
Julian Oes
2026-07-01 11:40:18 +12:00
committed by Ramon Roche
parent 99c1eb8123
commit 358b090c4e

View File

@@ -368,18 +368,23 @@ int main(int argc, char **argv)
register_sig_handler();
set_cpu_scaling();
px4_daemon::Server server(instance);
server.start();
ret = create_dirs();
if (ret != PX4_OK) {
return ret;
}
// Initialize PX4 (uORB, work queues, logging, ...) before starting the
// daemon server. The server's client-handler thread spawns module tasks
// (e.g. dataman), so platform init must happen-before that thread is
// created. Otherwise those tasks race on globals such as the uORB::Manager
// instance pointer and the log message advertisement.
px4::init_once();
px4::init(argc, argv, "px4");
px4_daemon::Server server(instance);
server.start();
// Don't set this up until PX4 is up and running
ret = set_server_running(instance);