1 #include <unistd.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <sys/utsname.h> 5 #include "android/kvm.h" 6 #include "android/utils/debug.h" 7 8 #define D(...) VERBOSE_PRINT(init,__VA_ARGS__) 9 10 /* A simple routine used to check that we can run the program under KVM. 11 * We simply want to ensure that the kvm driver is loaded and that the 12 * corresponding device file is accessible by the user. 13 */ 14 15 #ifndef __linux__ 16 #error "This file should only be compiled under linux" 17 #endif 18 19 int kvm_check_allowed(void)20kvm_check_allowed(void) 21 { 22 23 char* kvm_device = getenv(KVM_DEVICE_NAME_ENV); 24 if (NULL == kvm_device) { 25 kvm_device = "/dev/kvm"; 26 } 27 /* Is there a /dev/kvm device file here? */ 28 if (access(kvm_device,F_OK)) { 29 /* no need to print a warning here */ 30 D("No kvm device file detected"); 31 return 0; 32 } 33 34 /* Can we access it? */ 35 if (access(kvm_device,R_OK)) { 36 D("KVM device file is not readable for this user."); 37 return 0; 38 } 39 40 D("KVM mode auto-enabled!"); 41 return 1; 42 } 43 44