Commander: Time out if not starting successfully

This commit is contained in:
Lorenz Meier 2015-08-11 09:24:13 +02:00
parent 825880ab55
commit 134c1d991a
1 changed files with 11 additions and 4 deletions

View File

@ -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")) {