mirror of
https://git.FreeBSD.org/src.git
synced 2025-02-09 02:26:27 +00:00
Detect virtual machines on FreeBSD using the kern.vm_guest sysctl
kern.vm_guest == none -> not a virtual machine It's a bit of a misnomer with the function being named `isQEMU`... but FreeBSD's support seems to be a bit more all-encompassing than NetBSD's is today. Sponsored by: EMC / Isilon Storage Division
This commit is contained in:
parent
ed04e0c3dc
commit
aaf3e744fd
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/projects/netbsd-tests-update-12/; revision=304830
@ -41,6 +41,30 @@
|
||||
|
||||
static __inline bool
|
||||
isQEMU(void) {
|
||||
#ifdef __FreeBSD__
|
||||
char *vm_guest_name_buf;
|
||||
size_t len;
|
||||
bool is_vm;
|
||||
|
||||
if (sysctlbyname("kern.vm_guest", NULL, &len, NULL, 0) == -1)
|
||||
err(EXIT_FAILURE, "sysctl");
|
||||
|
||||
if ((vm_guest_name_buf = malloc(len)) == NULL)
|
||||
err(EXIT_FAILURE, "malloc");
|
||||
|
||||
if (sysctlbyname("kern.vm_guest", vm_guest_name_buf, &len, NULL, 0)
|
||||
== -1)
|
||||
err(EXIT_FAILURE, "sysctl");
|
||||
|
||||
if (strcmp(vm_guest_name_buf, "none") == 0)
|
||||
is_vm = false;
|
||||
else
|
||||
is_vm = true;
|
||||
|
||||
free(vm_guest_name_buf);
|
||||
|
||||
return is_vm;
|
||||
#else
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
char name[1024];
|
||||
size_t len = sizeof(name);
|
||||
@ -54,6 +78,7 @@ isQEMU(void) {
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
|
Loading…
x
Reference in New Issue
Block a user