From 134c1d991a6a003f5079d84b8a623f6f703cc2e1 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Tue, 11 Aug 2015 09:24:13 +0200 Subject: [PATCH] Commander: Time out if not starting successfully --- src/modules/commander/commander.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/modules/commander/commander.cpp b/src/modules/commander/commander.cpp index 57e175ed19..a01b33087f 100644 --- a/src/modules/commander/commander.cpp +++ b/src/modules/commander/commander.cpp @@ -275,7 +275,7 @@ int commander_main(int argc, char *argv[]) if (!strcmp(argv[1], "start")) { if (thread_running) { - warnx("commander already running"); + warnx("already running"); /* this is not an error */ exit(0); } @@ -288,11 +288,18 @@ int commander_main(int argc, char *argv[]) commander_thread_main, (argv) ? (char * const *)&argv[2] : (char * const *)NULL); - while (!thread_running) { - usleep(200); + unsigned constexpr max_wait_us = 1000000; + unsigned constexpr max_wait_steps = 2000; + + unsigned i; + for (i = 0; i < max_wait_steps; i++) { + usleep(max_wait_us / max_wait_steps); + if (thread_running) { + break; + } } - exit(0); + exit(!(i < max_wait_steps)); } if (!strcmp(argv[1], "stop")) {