Created
July 30, 2012 04:17
-
-
Save cosmo0920/3204517 to your computer and use it in GitHub Desktop.
/dev/vmmが存在した時にvmmctl --destroyするとホストがカーネルパニックを起こすのでそれをvmmctlから食い止める:コンパイルを通るようにした
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- vmmctl.c.orig 2012-05-03 14:04:37.000000000 +0900 | |
+++ vmmctl.c 2012-08-08 00:31:25.291915647 +0900 | |
@@ -47,6 +47,8 @@ | |
#include <machine/vmm.h> | |
#include <vmmapi.h> | |
+#include <dirent.h> | |
+#include <ctype.h> | |
#include "intel/vmcs.h" | |
@@ -59,6 +61,7 @@ | |
static const char *progname; | |
+static int vmmdir(void); | |
static void | |
usage(void) | |
{ | |
@@ -244,6 +247,7 @@ | |
static uint64_t desc_base; | |
static uint32_t desc_limit, desc_access; | |
+char buf[80]; | |
static void | |
dump_vm_run_exitcode(struct vm_exit *vmexit, int vcpu) | |
@@ -342,6 +346,18 @@ | |
return (vm_set_register(ctx, vcpu, VMCS_IDENT(field), val)); | |
} | |
+static int vmmdir() | |
+{ | |
+ DIR *dp; | |
+ char *path = "/dev/vmm"; | |
+ if((dp = opendir(path)) == NULL) { | |
+ (void)closedir(dp); | |
+ return (1); | |
+ } | |
+ (void)closedir(dp); | |
+ return (0); | |
+} | |
+ | |
enum { | |
VMNAME = 1000, /* avoid collision with return values from getopt */ | |
VCPU, | |
@@ -1478,6 +1494,25 @@ | |
if (error) | |
printf("errno = %d\n", errno); | |
+ if (!error && vmmdir()) { | |
+ printf("warn: /dev/vmm exist!\n"); | |
+ if (fgets(buf, sizeof(buf), stdin) == NULL) { | |
+ fprintf(stderr, "Input error\n"); | |
+ exit(1); | |
+ } | |
+ if (strchr(buf, '\n') != NULL) { | |
+ buf[strlen(buf) - 1] = '\0'; | |
+ } else { | |
+ fprintf(stderr, "too many input(>80)\n"); | |
+ exit(1); | |
+ } | |
+ printf("Do you execute \"vmmctl --destroy\" ?(Y/N)"); | |
+ if (toupper(getchar()) == 'Y') { | |
+ } else { | |
+ exit(error); | |
+ } | |
+ } | |
+ | |
if (!error && destroy) | |
vm_destroy(ctx); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment