1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
diff --git a/apps/misc.c b/apps/misc.c
index 3dfc289..c4f1831 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -256,7 +256,10 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter)
     (void)parameter;
     bookmark_autobookmark(false);
     call_storage_idle_notifys(true);
+/*
     exit(0);
+*/
+    printf("%s()\n", __func__);
 #else
     long msg_id = -1;
     int i;
diff --git a/firmware/target/hosted/sdl/button-sdl.c b/firmware/target/hosted/sdl/button-sdl.c
index 629d3aa..f5c3a40 100644
--- a/firmware/target/hosted/sdl/button-sdl.c
+++ b/firmware/target/hosted/sdl/button-sdl.c
@@ -176,9 +176,7 @@ void gui_message_loop(void)
             case SDL_QUIT:
             {
                 sim_exit_irq_handler();
-                SDL_Quit();
-                exit(EXIT_SUCCESS);
-                break;
+                return;
             }
             default:
                 /*printf("Unhandled event\n"); */
diff --git a/firmware/target/hosted/sdl/system-sdl.c b/firmware/target/hosted/sdl/system-sdl.c
index 7ab6fd2..8156b76 100644
--- a/firmware/target/hosted/sdl/system-sdl.c
+++ b/firmware/target/hosted/sdl/system-sdl.c
@@ -64,11 +64,13 @@ int wps_verbose_level = 3;

 void sys_poweroff(void)
 {
+    printf("hello\n");
     /* Order here is relevent to prevent deadlocks and use of destroyed
        sync primitives by kernel threads */
     sim_thread_shutdown();
     sim_kernel_shutdown();
     SDL_Quit();
+    exit(0);
 }

 /*
@@ -148,13 +150,14 @@ static int sdl_event_thread(void * param)
     SDL_AddTimer(100, cond_signal, param);
     /*
      * finally enter the button loop */
-    while(1)
-        gui_message_loop();
+    gui_message_loop();
+
+    /* if the above returns, we got SDL_QUIT */
+    queue_broadcast(SYS_POWEROFF, 0);

     return 0;
 }

-
 void system_init(void)
 {
     SDL_cond *c;