[tip:tools/kvm] kvm tools: Don' t panic guest when exiting from custom rootfs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Commit-ID:  509a9f5279126e1cdc556cf6a7ea5dcdc3b95aa7
Gitweb:     http://git.kernel.org/tip/509a9f5279126e1cdc556cf6a7ea5dcdc3b95aa7
Author:     Sasha Levin <levinsasha928@xxxxxxxxx>
AuthorDate: Tue, 20 Dec 2011 12:23:20 +0200
Committer:  Pekka Enberg <penberg@xxxxxxxxxx>
CommitDate: Wed, 21 Dec 2011 22:28:16 +0200

kvm tools: Don't panic guest when exiting from custom rootfs

We currently panic guest when exiting from custom rootfs since at that point
we terminate init, and the guest kernel doesn't quite like that.

Instead, we do a graceful shutdown when init is done (either when 'lkvm
sandbox' command or '/bin/sh' is finished).

Signed-off-by: Sasha Levin <levinsasha928@xxxxxxxxx>
Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx>
---
 tools/kvm/guest/init_stage2.c |   24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/tools/kvm/guest/init_stage2.c b/tools/kvm/guest/init_stage2.c
index 6489fee..7b96436 100644
--- a/tools/kvm/guest/init_stage2.c
+++ b/tools/kvm/guest/init_stage2.c
@@ -7,6 +7,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <errno.h>
+#include <linux/reboot.h>
 
 static int run_process(char *filename)
 {
@@ -26,6 +27,9 @@ static int run_process_sandbox(char *filename)
 
 int main(int argc, char *argv[])
 {
+	pid_t child;
+	int status;
+
 	/* get session leader */
 	setsid();
 
@@ -34,12 +38,20 @@ int main(int argc, char *argv[])
 
 	puts("Starting '/bin/sh'...");
 
-	if (access("/virt/sandbox.sh", R_OK) == 0)
-		run_process_sandbox("/bin/sh");
-	else
-		run_process("/bin/sh");
-
-	printf("Init failed: %s\n", strerror(errno));
+	child = fork();
+	if (child < 0) {
+		printf("Fatal: fork() failed with %d\n", child);
+		return 0;
+	} else if (child == 0) {
+		if (access("/virt/sandbox.sh", R_OK) == 0)
+			run_process_sandbox("/bin/sh");
+		else
+			run_process("/bin/sh");
+	} else {
+		wait(&status);
+	}
+
+	reboot(LINUX_REBOOT_CMD_RESTART);
 
 	return 0;
 }
--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux