exit cleanly
authorJulien Desfossez <jdesfossez@efficios.com>
Fri, 17 Aug 2012 16:30:05 +0000 (12:30 -0400)
committerJulien Desfossez <jdesfossez@efficios.com>
Sat, 19 Oct 2013 16:02:38 +0000 (12:02 -0400)
Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
src/common.h
src/cursesdisplay.c
src/lttngtop.c

index 3738331..1bde45c 100644 (file)
@@ -31,6 +31,8 @@ sem_t goodtodisplay, goodtoupdate, timer, pause_sem, end_trace_sem, bootstrap;
 GPtrArray *copies; /* struct lttngtop */
 GHashTable *global_perf_liszt;
 
+extern int quit;
+
 struct lttngtop *data;
 
 struct processtop *find_process_tid(struct lttngtop *ctx, int pid, char *comm);
index 25fe1f9..c8ac5db 100644 (file)
@@ -74,11 +74,13 @@ void reset_ncurses()
 {
        curs_set(1);
        endwin();
-       exit(0);
+       quit = 1;
 }
 
 static void handle_sigterm(int signal)
 {
+       fprintf(stderr, "caugh signal\n");
+       pthread_cancel(keyboard_thread);
        reset_ncurses();
 }
 
@@ -119,6 +121,7 @@ void init_screen()
                define_key("\033[17;2~", KEY_F(18));
        }
        signal(SIGTERM, handle_sigterm);
+       signal(SIGINT, handle_sigterm);
        mousemask(BUTTON1_CLICKED, NULL);
        refresh();
 }
@@ -1491,6 +1494,8 @@ void *handle_keyboard(void *p)
                case KEY_F(10):
                case 'q':
                        reset_ncurses();
+                       /* exit keyboard thread */
+                       pthread_exit(0);
                        break;
                case 't':
                        toggle_threads *= -1;
@@ -1502,7 +1507,6 @@ void *handle_keyboard(void *p)
                        } else {
                                resume_display();
                        }
-                       break;
                case 'r':
                        toggle_pref_panel();
                        break;
index 7d89e5c..8a3416c 100644 (file)
 const char *opt_input_path;
 int opt_textdump;
 
+int quit = 0;
+
 struct lttngtop *copy;
 pthread_t display_thread;
 pthread_t timer_thread;
 
 unsigned long refresh_display = 1 * NSEC_PER_SEC;
 unsigned long last_display_update = 0;
-int quit = 0;
 
 /* list of FDs available for being read with snapshots */
 struct mmap_stream_list mmap_list;
@@ -91,8 +92,12 @@ void *refresh_thread(void *p)
        struct mmap_stream *mmap_info;
 
        while (1) {
-               if (quit)
-                       return NULL;
+               if (quit) {
+                       sem_post(&pause_sem);
+                       sem_post(&timer);
+                       sem_post(&goodtodisplay);
+                       pthread_exit(0);
+               }
                bt_list_for_each_entry(mmap_info, &mmap_list.head, list)
                        helper_kernctl_buffer_flush(mmap_info->fd);
                sem_wait(&pause_sem);
@@ -118,17 +123,18 @@ void *ncurses_display(void *p)
                sem_wait(&goodtodisplay);
                sem_wait(&pause_sem);
 
+               if (quit) {
+                       reset_ncurses();
+                       pthread_exit(0);
+               }
+
+
                copy = g_ptr_array_index(copies, current_display_index);
                assert(copy);
                display(current_display_index++);
 
                sem_post(&goodtoupdate);
                sem_post(&pause_sem);
-
-               if (quit) {
-                       reset_ncurses();
-                       pthread_exit(0);
-               }
        }
 }
 
@@ -468,7 +474,9 @@ void iter_trace(struct bt_context *bt_ctx)
                                NULL, NULL, NULL);
        }
 
-       while ((event = bt_ctf_iter_read_event(iter)) != NULL) {
+       while (((event = bt_ctf_iter_read_event(iter)) != NULL)) {
+               if (quit)
+                       goto end_iter;
                ret = bt_iter_next(bt_ctf_get_iter(iter));
                if (ret < 0)
                        goto end_iter;
@@ -956,9 +964,9 @@ int main(int argc, char **argv)
                live_consume(&bt_ctx);
                iter_trace(bt_ctx);
 
+               pthread_join(timer_thread, NULL);
                quit = 1;
                pthread_join(display_thread, NULL);
-               pthread_join(timer_thread, NULL);
 
                lttng_stop_tracing("test");
                lttng_destroy_session("test");
@@ -984,8 +992,8 @@ int main(int argc, char **argv)
 
                iter_trace(bt_ctx);
 
-               quit = 1;
                pthread_join(display_thread, NULL);
+               quit = 1;
                pthread_join(timer_thread, NULL);
        }
 
This page took 0.033372 seconds and 4 git commands to generate.