svn commit: r304830 - projects/netbsd-tests-update-12/contrib/netbsd-tests/lib/libc/gen
Garrett Cooper
ngie at FreeBSD.org
Fri Aug 26 03:46:44 UTC 2016
Author: ngie
Date: Fri Aug 26 03:46:43 2016
New Revision: 304830
URL: https://svnweb.freebsd.org/changeset/base/304830
Log:
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
Modified:
projects/netbsd-tests-update-12/contrib/netbsd-tests/lib/libc/gen/isqemu.h
Modified: projects/netbsd-tests-update-12/contrib/netbsd-tests/lib/libc/gen/isqemu.h
==============================================================================
--- projects/netbsd-tests-update-12/contrib/netbsd-tests/lib/libc/gen/isqemu.h Fri Aug 26 03:36:37 2016 (r304829)
+++ projects/netbsd-tests-update-12/contrib/netbsd-tests/lib/libc/gen/isqemu.h Fri Aug 26 03:46:43 2016 (r304830)
@@ -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
More information about the svn-src-projects
mailing list