blob: 76d5a552bcfc5907b5811e35b7a1be18d6c8a494 [file] [log] [blame]
David 'Digit' Turner36597752011-05-20 01:18:01 +02001#include <unistd.h>
2#include <string.h>
3#include <sys/utsname.h>
4#include "android/utils/debug.h"
5
6#define D(...) VERBOSE_PRINT(init,__VA_ARGS__)
7
8/* A simple routine used to check that we can run the program under KVM.
David 'Digit' Turner80ab3272011-05-30 21:40:26 +02009 * We simply want to ensure that the kvm driver is loaded and that the
10 * corresponding device file is accessible by the user.
David 'Digit' Turner36597752011-05-20 01:18:01 +020011 */
12
13#ifndef __linux__
14#error "This file should only be compiled under linux"
15#endif
16
17int
18kvm_check_allowed(void)
19{
David 'Digit' Turner36597752011-05-20 01:18:01 +020020 /* Is there a /dev/kvm device file here? */
21 if (access("/dev/kvm",F_OK)) {
22 /* no need to print a warning here */
23 D("No kvm device file detected");
24 return 0;
25 }
26
27 /* Can we access it? */
28 if (access("/dev/kvm",R_OK)) {
29 D("KVM device file is not readable for this user.");
30 return 0;
31 }
32
David 'Digit' Turner36597752011-05-20 01:18:01 +020033 D("KVM mode auto-enabled!");
34 return 1;
35}
36