From f74c7b5a93c75e6b7518f2f34f3b662151277c84 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Tue, 26 May 2020 22:50:56 -0500 Subject: hscript: Ensure target mounts aren't hardcoded to /target --- hscript/script_e.cc | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'hscript') diff --git a/hscript/script_e.cc b/hscript/script_e.cc index 829d672..8c857d7 100644 --- a/hscript/script_e.cc +++ b/hscript/script_e.cc @@ -162,25 +162,29 @@ bool Script::execute() const { if(opts.test(InstallEnvironment)) ped_device_free_all(); if(!opts.test(Simulate)) { - if(!fs::exists(targetDirectory() + "/dev", ec)) { - fs::create_directory(targetDirectory() + "/dev", ec); + const std::string devpath = targetDirectory() + "/dev"; + const std::string procpath = targetDirectory() + "/proc"; + const std::string syspath = targetDirectory() + "/sys"; + + if(!fs::exists(devpath, ec)) { + fs::create_directory(devpath, ec); } - if(mount("/dev", "/target/dev", nullptr, MS_BIND, nullptr) != 0) { + if(mount("/dev", devpath.c_str(), nullptr, MS_BIND, nullptr) != 0) { output_warning("internal", "could not bind-mount /dev; " "bootloader configuration may fail"); } - if(!fs::exists(targetDirectory() + "/proc", ec)) { - fs::create_directory(targetDirectory() + "/proc", ec); + if(!fs::exists(procpath, ec)) { + fs::create_directory(procpath, ec); } - if(mount("none", "/target/proc", "proc", 0, nullptr) != 0) { + if(mount("none", procpath.c_str(), "proc", 0, nullptr) != 0) { output_warning("internal", "target procfs could not be mounted"); } - if(!fs::exists(targetDirectory() + "/sys", ec)) { - fs::create_directory(targetDirectory() + "/sys", ec); + if(!fs::exists(syspath, ec)) { + fs::create_directory(syspath, ec); } - if(mount("none", "/target/sys", "sysfs", 0, nullptr) != 0) { + if(mount("none", syspath.c_str(), "sysfs", 0, nullptr) != 0) { output_warning("internal", "target sysfs could not be mounted"); } } -- cgit v1.2.3-70-g09d2