aboutsummaryrefslogtreecommitdiffstats
path: root/kvm-android.c
blob: 76d5a552bcfc5907b5811e35b7a1be18d6c8a494 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <unistd.h>
#include <string.h>
#include <sys/utsname.h>
#include "android/utils/debug.h"

#define D(...) VERBOSE_PRINT(init,__VA_ARGS__)

/* A simple routine used to check that we can run the program under KVM.
 * We simply want to ensure that the kvm driver is loaded and that the
 * corresponding device file is accessible by the user.
 */

#ifndef __linux__
#error "This file should only be compiled under linux"
#endif

int
kvm_check_allowed(void)
{
    /* Is there a /dev/kvm device file here? */
    if (access("/dev/kvm",F_OK)) {
        /* no need to print a warning here */
        D("No kvm device file detected");
        return 0;
    }

    /* Can we access it? */
    if (access("/dev/kvm",R_OK)) {
        D("KVM device file is not readable for this user.");
        return 0;
    }

    D("KVM mode auto-enabled!");
    return 1;
}