From cfafee2020846aeb307235c5bfe2d84a08e9632e Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 22 Jan 2025 13:14:40 -0800 Subject: [PATCH 1/3] vboxwrapper: actually create the 'virtualbox home directory' As far as I can tell this dir is used only on Win; we run VBoxSVC.exe there, and look for a log file later. Should we remove it for other platforms? Also: there's some code to create a 'scratch' dir, projects/scratch. This seems like a bad idea; we shouldn't put random stuff in projects/, and also if there are multiple VM jobs they share the same dir. Should we get rid of this? --- samples/vboxwrapper/vbox_vboxmanage.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/samples/vboxwrapper/vbox_vboxmanage.cpp b/samples/vboxwrapper/vbox_vboxmanage.cpp index 1a0068d936..5ff09505bb 100644 --- a/samples/vboxwrapper/vbox_vboxmanage.cpp +++ b/samples/vboxwrapper/vbox_vboxmanage.cpp @@ -101,14 +101,20 @@ int VBOX_VM::initialize() { #endif // Determine the 'VirtualBox home directory'. + // On Windows, we run VboxSVC.exe in this directory, + // and we look for its log file there. + // On other platforms I don't think this is used. + // // NOTE: I'm not sure this is relevant; see // https://docs.oracle.com/en/virtualization/virtualbox/6.1/admin/TechnicalBackground.html#3.1.3.-Summary-of-Configuration-Data-Locations // if (getenv("VBOX_USER_HOME")) { virtualbox_home_directory = getenv("VBOX_USER_HOME"); } else { - // If the override environment variable isn't specified then - // it is based of the current users HOME directory. + // If not specified by environment variable then create it + // Win, Linux: under user home dir + // Mac: in BOINC data dir + // const char *home; #ifdef _WIN32 home = getenv("USERPROFILE"); @@ -126,6 +132,7 @@ int VBOX_VM::initialize() { #endif virtualbox_home_directory = home; virtualbox_home_directory += "/.VirtualBox"; + boinc_mkdir(virtualbox_home_directory.c_str()); } #ifdef _WIN32 From ac0c231f8d2c448b13610be28f048434dabe2f89 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 23 Jan 2025 16:51:44 -0800 Subject: [PATCH 2/3] vboxwrapper: put log directory (.VirtualBox) in project dir The 'VBox home directory' is where VBox writes log files (which are read by vboxwrapper). If this is not specified by the env var VBOX_USER_HOME, we need to create it somewhere and set the env var to point there. Previously we put it in /projects. That's no good because it's not a project, and the client erased it. We also tried putting it in the (real) user's home dir. That's no good because 1) we shouldn't mess with the home dir 2) in sandboxed configs we're running as user 'boinc_projects', and don't have access to the home dir. According to https://boinc.berkeley.edu/sandbox_design.php, the only places 'boinc_projects' can write are projects/, slots/, and their subdirectories. So the logical places to put .VirtualBox are this job's slot directory, or its project directory. I chose the latter. --- samples/vboxwrapper/vbox_vboxmanage.cpp | 48 +++++++++++++------------ 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/samples/vboxwrapper/vbox_vboxmanage.cpp b/samples/vboxwrapper/vbox_vboxmanage.cpp index 5ff09505bb..521fdc8fdb 100644 --- a/samples/vboxwrapper/vbox_vboxmanage.cpp +++ b/samples/vboxwrapper/vbox_vboxmanage.cpp @@ -101,38 +101,42 @@ int VBOX_VM::initialize() { #endif // Determine the 'VirtualBox home directory'. - // On Windows, we run VboxSVC.exe in this directory, - // and we look for its log file there. - // On other platforms I don't think this is used. + // We run VboxSVC.exe here, and look for its log file here. // - // NOTE: I'm not sure this is relevant; see + // See // https://docs.oracle.com/en/virtualization/virtualbox/6.1/admin/TechnicalBackground.html#3.1.3.-Summary-of-Configuration-Data-Locations + + // Check if specified by environment variable // - if (getenv("VBOX_USER_HOME")) { - virtualbox_home_directory = getenv("VBOX_USER_HOME"); + char *p = getenv("VBOX_USER_HOME"); + if (p) { + virtualbox_home_directory = p; } else { - // If not specified by environment variable then create it - // Win, Linux: under user home dir - // Mac: in BOINC data dir + // If not then make one in the project dir. + // Note: in a sandboxed config (e.g. Mac) we're running + // as effective user 'boinc_project'. + // This user doesn't have write access to the (real user) home dir + // or the BOINC data directory. + // But it can write to slots/, slots/*/, projects/ and projects/*/. + // Use the latter. // - const char *home; + virtualbox_home_directory = aid.project_dir; + virtualbox_home_directory += "/.VirtualBox"; + + // create if not there already + boinc_mkdir(virtualbox_home_directory.c_str()); + + // set env var telling VBox where to put log file #ifdef _WIN32 - home = getenv("USERPROFILE"); - if (home == NULL) { - vboxlog_msg("no USERPROFILE - exiting"); - exit(1); + if (!SetEnvironmentVariable("VBOX_USER_HOME", const_cast(virtualbox_home_directory.c_str()))) { + vboxlog_msg("Failed to modify the search path."); } -#elif __APPLE__ - home = "/Library/Application Support/BOINC Data"; #else - home = getenv("HOME"); - if (home == NULL) { - home = getpwuid(getuid())->pw_dir; + // putenv does not copy its input buffer, so we must use setenv + if (setenv("VBOX_USER_HOME", const_cast(virtualbox_home_directory.c_str()), 1)) { + vboxlog_msg("Failed to modify the VBOX_USER_HOME path."); } #endif - virtualbox_home_directory = home; - virtualbox_home_directory += "/.VirtualBox"; - boinc_mkdir(virtualbox_home_directory.c_str()); } #ifdef _WIN32 From a2cfc10ca795e7d8bda8530af4451546ec97b4e4 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 24 Jan 2025 02:43:55 -0800 Subject: [PATCH 3/3] vboxwrapper: put .VirtualBox in the BOINC data dir, not the project dir. Note: there's a single instance of VBoxSVC, not one per job. --- samples/vboxwrapper/vbox_vboxmanage.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/samples/vboxwrapper/vbox_vboxmanage.cpp b/samples/vboxwrapper/vbox_vboxmanage.cpp index 521fdc8fdb..8cbed18e92 100644 --- a/samples/vboxwrapper/vbox_vboxmanage.cpp +++ b/samples/vboxwrapper/vbox_vboxmanage.cpp @@ -112,15 +112,11 @@ int VBOX_VM::initialize() { if (p) { virtualbox_home_directory = p; } else { - // If not then make one in the project dir. - // Note: in a sandboxed config (e.g. Mac) we're running - // as effective user 'boinc_project'. - // This user doesn't have write access to the (real user) home dir - // or the BOINC data directory. - // But it can write to slots/, slots/*/, projects/ and projects/*/. - // Use the latter. + // If not then make one in the BOINC data directory. + // Note: in a sandboxed config we're running as user 'boinc_project'. + // This user doesn't have write access to the (real user) home dir. // - virtualbox_home_directory = aid.project_dir; + virtualbox_home_directory = aid.boinc_dir; virtualbox_home_directory += "/.VirtualBox"; // create if not there already