]> xenbits.xensource.com Git - people/liuw/mini-os.git/commitdiff
mini-os: fixed shutdown thread
authorThomas Leonard <talex5@gmail.com>
Thu, 26 Jun 2014 11:28:19 +0000 (12:28 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Fri, 27 Jun 2014 12:38:33 +0000 (13:38 +0100)
Before, it read "" and started a shutdown immediately. Now, it waits for
a non-empty value and then actually shuts down.

Acked-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
[talex5@gmail.com: avoid declaration-after-statement in kernel.c]
Signed-off-by: Thomas Leonard <talex5@gmail.com>
kernel.c
main.c

index ea409f4a817027e8e321b7f269e08e4c6892913d..c7410db824f463f8d16babb9c2970e4a56cb03cc 100644 (file)
--- a/kernel.c
+++ b/kernel.c
@@ -68,7 +68,9 @@ void setup_xen_features(void)
 /* This should be overridden by the application we are linked against. */
 __attribute__((weak)) void app_shutdown(unsigned reason)
 {
+    struct sched_shutdown sched_shutdown = { .reason = reason };
     printk("Shutdown requested: %d\n", reason);
+    HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
 }
 
 static void shutdown_thread(void *p)
@@ -76,12 +78,14 @@ static void shutdown_thread(void *p)
     const char *path = "control/shutdown";
     const char *token = path;
     xenbus_event_queue events = NULL;
-    char *shutdown, *err;
+    char *shutdown = NULL, *err;
     unsigned int shutdown_reason;
     xenbus_watch_path_token(XBT_NIL, path, token, &events);
-    while ((err = xenbus_read(XBT_NIL, path, &shutdown)) != NULL)
+    while ((err = xenbus_read(XBT_NIL, path, &shutdown)) != NULL || !strcmp(shutdown, ""))
     {
         free(err);
+        free(shutdown);
+        shutdown = NULL;
         xenbus_wait_for_watch(&events);
     }
     err = xenbus_unwatch_path_token(XBT_NIL, path, token);
@@ -106,7 +110,7 @@ static void shutdown_thread(void *p)
 /* This should be overridden by the application we are linked against. */
 __attribute__((weak)) int app_main(start_info_t *si)
 {
-    printk("Dummy main: start_info=%p\n", si);
+    printk("kernel.c: dummy main: start_info=%p\n", si);
     return 0;
 }
 
diff --git a/main.c b/main.c
index 73eb6fb234476d4d6a5eed4c55944ccfbe529375..aec05864d3a97e36df5d4d8c64bb2bd1d1ea57a8 100644 (file)
--- a/main.c
+++ b/main.c
@@ -185,7 +185,7 @@ void _exit(int ret)
 
 int app_main(start_info_t *si)
 {
-    printk("Dummy main: start_info=%p\n", si);
+    printk("main.c: dummy main: start_info=%p\n", si);
     main_thread = create_thread("main", call_main, si);
     return 0;
 }