diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2013-09-08 20:05:38 +0200 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2013-09-08 20:05:38 +0200 |
commit | c3bb6960e6f85d07d65fefdfebfdc0650e81aa92 (patch) | |
tree | 105912b892a8955aaeb3e8fd6623ff45f6fbcea4 /src/modules | |
parent | 56a35cc8896b077e70226541a43aa0d449e8d9bb (diff) | |
download | px4-firmware-c3bb6960e6f85d07d65fefdfebfdc0650e81aa92.tar.gz px4-firmware-c3bb6960e6f85d07d65fefdfebfdc0650e81aa92.tar.bz2 px4-firmware-c3bb6960e6f85d07d65fefdfebfdc0650e81aa92.zip |
Fixed mavlink start / stop to ensure process is in a sane state once NSH return
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/mavlink/mavlink.c | 16 | ||||
-rw-r--r-- | src/modules/mavlink/mavlink_receiver.cpp | 2 | ||||
-rw-r--r-- | src/modules/mavlink/orb_listener.c | 2 |
3 files changed, 17 insertions, 3 deletions
diff --git a/src/modules/mavlink/mavlink.c b/src/modules/mavlink/mavlink.c index 5eb7cba9b..cbcd4adfb 100644 --- a/src/modules/mavlink/mavlink.c +++ b/src/modules/mavlink/mavlink.c @@ -743,7 +743,7 @@ int mavlink_thread_main(int argc, char *argv[]) thread_running = false; - exit(0); + return 0; } static void @@ -767,7 +767,7 @@ int mavlink_main(int argc, char *argv[]) /* this is not an error */ if (thread_running) - errx(0, "mavlink already running\n"); + errx(0, "mavlink already running"); thread_should_exit = false; mavlink_task = task_spawn_cmd("mavlink", @@ -776,15 +776,25 @@ int mavlink_main(int argc, char *argv[]) 2048, mavlink_thread_main, (const char **)argv); + + while (!thread_running) { + usleep(200); + } + exit(0); } if (!strcmp(argv[1], "stop")) { + + /* this is not an error */ + if (!thread_running) + errx(0, "mavlink already stopped"); + thread_should_exit = true; while (thread_running) { usleep(200000); - printf("."); + warnx("."); } warnx("terminated."); diff --git a/src/modules/mavlink/mavlink_receiver.cpp b/src/modules/mavlink/mavlink_receiver.cpp index 4674f7a24..222d1f45f 100644 --- a/src/modules/mavlink/mavlink_receiver.cpp +++ b/src/modules/mavlink/mavlink_receiver.cpp @@ -755,5 +755,7 @@ receive_start(int uart) pthread_t thread; pthread_create(&thread, &receiveloop_attr, receive_thread, &uart); + + pthread_attr_destroy(&receiveloop_attr); return thread; } diff --git a/src/modules/mavlink/orb_listener.c b/src/modules/mavlink/orb_listener.c index 53d86ec00..d11a67fc6 100644 --- a/src/modules/mavlink/orb_listener.c +++ b/src/modules/mavlink/orb_listener.c @@ -829,5 +829,7 @@ uorb_receive_start(void) pthread_t thread; pthread_create(&thread, &uorb_attr, uorb_receive_thread, NULL); + + pthread_attr_destroy(&uorb_attr); return thread; } |