1#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.
9 * We simply want to ensure that the kvm driver is loaded and that the
10 * corresponding device file is accessible by the user.
11 */
12
13#ifndef __linux__
14#error "This file should only be compiled under linux"
15#endif
16
17int
18kvm_check_allowed(void)
19{
20    /* 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
33    D("KVM mode auto-enabled!");
34    return 1;
35}
36
37