diff --git a/samples/vboxwrapper/vbox_common.cpp b/samples/vboxwrapper/vbox_common.cpp index 2b1bd304435284a9bdaf3d658a3729519cefbc8c..7221b054d45880a56d127c4b04dbb2520db73e0f 100644 --- a/samples/vboxwrapper/vbox_common.cpp +++ b/samples/vboxwrapper/vbox_common.cpp @@ -74,8 +74,7 @@ static bool is_timestamp_newer(VBOX_TIMESTAMP& t1, VBOX_TIMESTAMP& t2) { VBOX_BASE::VBOX_BASE() : VBOX_JOB() { VBOX_JOB::clear(); - virtualbox_home_directory.clear(); - virtualbox_scratch_directory.clear(); + virtualbox_profile_directory.clear(); virtualbox_install_directory.clear(); virtualbox_guest_additions.clear(); virtualbox_version_raw.clear(); @@ -599,7 +598,7 @@ int VBOX_BASE::get_system_log( int retval = BOINC_SUCCESS; // Locate and read log file - virtualbox_system_log = virtualbox_home_directory + "/VBoxSVC.log"; + virtualbox_system_log = virtualbox_profile_directory + "/VBoxSVC.log"; if (boinc_file_exists(virtualbox_system_log.c_str())) { if (tail_only) { diff --git a/samples/vboxwrapper/vbox_common.h b/samples/vboxwrapper/vbox_common.h index f668e4a8d999a4ce4db1128371199f4bc421a27c..521dabc801ab0cfcdc102f4e9b177cd66bbf29c3 100644 --- a/samples/vboxwrapper/vbox_common.h +++ b/samples/vboxwrapper/vbox_common.h @@ -108,10 +108,29 @@ struct VBOX_BASE : VBOX_JOB { VBOX_BASE(); ~VBOX_BASE(); - string virtualbox_home_directory; - string virtualbox_scratch_directory; + // Was 'virtualbox_home_directory' in previous releases. + // The directory where VirtualBox stores + // global configuration files and + // global logfiles such as VBoxSVC.log. + // It is user based and in the documentation sometimes + // referred to as "home", sometimes a "profile". + // Renamed since the latter seems to be more precise and a user can switch + // between different locations (=profiles) using the VBOX_USER_HOME environment variable. + // + string virtualbox_profile_directory; + + // Directory where VirtualBox installs it's executables. + // string virtualbox_install_directory; + + // Path where the VirtualBox Guest Additions iso file is located. + // Never mix "VirtualBox Guest Additions" with "VirtualBox Extension Pack". + // The first is part of the base package and to be installed in the guest VM, + // the latter is to be installed on the host OS and published under a different license. + // See the VirtualBox documentation for further details. + // string virtualbox_guest_additions; + string virtualbox_version_raw; string virtualbox_version_display; diff --git a/samples/vboxwrapper/vbox_vboxmanage.cpp b/samples/vboxwrapper/vbox_vboxmanage.cpp index 6fa839bfdea5ac45108329a5a8e2fcfe76a34c7e..ee6ee2dc6ec4d643d4d0a59a6bced611282e74b3 100644 --- a/samples/vboxwrapper/vbox_vboxmanage.cpp +++ b/samples/vboxwrapper/vbox_vboxmanage.cpp @@ -100,8 +100,10 @@ int VBOX_VM::initialize() { } #endif - // Determine the 'VirtualBox home directory'. - // We run VboxSVC.exe here, and look for its log file here. + // Determine the 'VirtualBox profile directory'. + // VboxSVC writes the main VM database and it's logfiles there. + // The default location is OS based as well as user based and + // can be modified via the VBOX_USER_HOME environment variable. // // See // https://docs.oracle.com/en/virtualization/virtualbox/6.1/admin/TechnicalBackground.html#3.1.3.-Summary-of-Configuration-Data-Locations @@ -110,9 +112,37 @@ int VBOX_VM::initialize() { // char *p = getenv("VBOX_USER_HOME"); if (p) { - virtualbox_home_directory = p; + virtualbox_profile_directory = p; } else { - // If not then make one in the BOINC project directory. +#ifdef _WIN32 + // Default vbox profile is located in '%USERPROFILE%\.VirtualBox'. + // Check for '%USERPROFILE%' instead, since the vbox profile dir + // doesn't exist until the user has started + // a VirtualBox component at least once. + // + string vbox_profile_dir = getenv("USERPROFILE"); + + if (vbox_profile_dir.size()) { + virtualbox_profile_directory = vbox_profile_dir; + virtualbox_profile_directory += "/.VirtualBox"; + + // If necessary VirtualBox automatically creates required dirs + // at the default locations. + // + } else { + // If '%USERPROFILE%' is not set. + // + virtualbox_profile_directory = aid.boinc_dir; + virtualbox_profile_directory += "/projects/VirtualBox"; + + // create if not there already + // + boinc_mkdir(virtualbox_profile_directory.c_str()); + } +#else +#ifdef __APPLE__ + // If 'VBOX_USER_HOME' is not set + // then make it point to the BOINC project directory. // Notes: // 1) we can't put it in the home dir; // in a sandboxed config we're running as user 'boinc_projects', @@ -120,20 +150,51 @@ int VBOX_VM::initialize() { // 2) we can't put it in the BOINC data dir. // boinc_projects can't write their either // - virtualbox_home_directory = aid.boinc_dir; - virtualbox_home_directory += "/projects/VirtualBox"; + virtualbox_profile_directory = aid.boinc_dir; + virtualbox_profile_directory += "/projects/VirtualBox"; // create if not there already - boinc_mkdir(virtualbox_home_directory.c_str()); + // + boinc_mkdir(virtualbox_profile_directory.c_str()); +#else + // Default vbox profile is located in '/home/user/.config/VirtualBox'. + // Check for '/home/user/.config' instead, since the vbox profile dir + // doesn't exist until the user has started + // a VirtualBox component at least once. + // + string linux_user = getenv("USER"); + string vbox_profile_dir = "/home/"; + vbox_profile_dir += linux_user; + vbox_profile_dir += "/.config"; + + if (is_dir(vbox_profile_dir.c_str())) { + virtualbox_profile_directory = vbox_profile_dir; + virtualbox_profile_directory += "/VirtualBox"; + + // If necessary VirtualBox automatically creates required dirs + // at the default locations. + // + } else { + // If BOINC runs as a service without a user's home directory. + // + virtualbox_profile_directory = aid.boinc_dir; + virtualbox_profile_directory += "/projects/VirtualBox"; + + // create if not there already + // + boinc_mkdir(virtualbox_profile_directory.c_str()); + } +#endif +#endif // set env var telling VBox where to put log file #ifdef _WIN32 - if (!SetEnvironmentVariable("VBOX_USER_HOME", const_cast<char*>(virtualbox_home_directory.c_str()))) { + if (!SetEnvironmentVariable("VBOX_USER_HOME", const_cast<char*>(virtualbox_profile_directory.c_str()))) { vboxlog_msg("Failed to modify the search path."); } #else // putenv does not copy its input buffer, so we must use setenv - if (setenv("VBOX_USER_HOME", const_cast<char*>(virtualbox_home_directory.c_str()), 1)) { + if (setenv("VBOX_USER_HOME", const_cast<char*>(virtualbox_profile_directory.c_str()), 1)) { vboxlog_msg("Failed to modify the VBOX_USER_HOME path."); } #endif