function Platform::isVirtualBoxGuest
Attempts detection of VirtualBox guest VMs
This works based on the process' user being "vagrant", the COMPOSER_RUNTIME_ENV env var being set to "virtualbox", or lsmod showing the virtualbox guest additions are loaded
1 call to Platform::isVirtualBoxGuest()
- Platform::workaroundFilesystemIssues in vendor/
composer/ composer/ src/ Composer/ Util/ Platform.php
File
-
vendor/
composer/ composer/ src/ Composer/ Util/ Platform.php, line 302
Class
- Platform
- Platform helper for uniform platform-specific tests.
Namespace
Composer\UtilCode
private static function isVirtualBoxGuest() : bool {
if (null === self::$isVirtualBoxGuest) {
self::$isVirtualBoxGuest = false;
if (self::isWindows()) {
return self::$isVirtualBoxGuest;
}
if (function_exists('posix_getpwuid') && function_exists('posix_geteuid')) {
$processUser = posix_getpwuid(posix_geteuid());
if (is_array($processUser) && $processUser['name'] === 'vagrant') {
return self::$isVirtualBoxGuest = true;
}
}
if (self::getEnv('COMPOSER_RUNTIME_ENV') === 'virtualbox') {
return self::$isVirtualBoxGuest = true;
}
if (defined('PHP_OS_FAMILY') && PHP_OS_FAMILY === 'Linux') {
$process = new ProcessExecutor();
try {
if (0 === $process->execute([
'lsmod',
], $output) && str_contains($output, 'vboxguest')) {
return self::$isVirtualBoxGuest = true;
}
} catch (\Exception $e) {
// noop
}
}
}
return self::$isVirtualBoxGuest;
}