From 9a56858367f6b6fac5de3f3c5b6f9515f97bb0ec Mon Sep 17 00:00:00 2001 From: "Ruan E. Formigoni" Date: Wed, 16 Oct 2024 11:59:18 -0300 Subject: [PATCH] Include busybox at the end of PATH --- src/boot/boot.cpp | 11 +++++++++-- src/boot/config/config.hpp | 5 ++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/boot/boot.cpp b/src/boot/boot.cpp index ec06d56..e2e1a6c 100644 --- a/src/boot/boot.cpp +++ b/src/boot/boot.cpp @@ -104,10 +104,17 @@ void relocate(char** argv) "Failed to create directory {}"_fmt(path_dir_app_bin) ); + // Create busybox dir + fs::path path_dir_busybox = path_dir_app_bin / "busybox"; + ethrow_if(not fs::exists(path_dir_busybox) and not fs::create_directories(path_dir_busybox), + "Failed to create directory {}"_fmt(path_dir_busybox) + ); + // Set variables ns_env::set("FIM_DIR_GLOBAL", path_dir_base.c_str(), ns_env::Replace::Y); ns_env::set("FIM_DIR_APP", path_dir_app.c_str(), ns_env::Replace::Y); ns_env::set("FIM_DIR_APP_BIN", path_dir_app_bin.c_str(), ns_env::Replace::Y); + ns_env::set("FIM_DIR_BUSYBOX", path_dir_busybox.c_str(), ns_env::Replace::Y); ns_env::set("FIM_FILE_BINARY", path_absolute.c_str(), ns_env::Replace::Y); // Create instance directory @@ -190,7 +197,7 @@ void relocate(char** argv) ethrow_if(not file_binary.is_open(), "Could not open flatimage binary file"); std::tie(offset_beg, offset_end) = f_write_from_header(path_dir_instance / "fim_boot" , 0); std::tie(offset_beg, offset_end) = f_write_from_offset(file_binary, path_dir_app_bin / "bash", offset_end); - std::tie(offset_beg, offset_end) = f_write_from_offset(file_binary, path_dir_app_bin / "busybox", offset_end); + std::tie(offset_beg, offset_end) = f_write_from_offset(file_binary, path_dir_busybox / "busybox", offset_end); std::tie(offset_beg, offset_end) = f_write_from_offset(file_binary, path_dir_app_bin / "bwrap", offset_end); std::tie(offset_beg, offset_end) = f_write_from_offset(file_binary, path_dir_app_bin / "ciopfs", offset_end); std::tie(offset_beg, offset_end) = f_write_from_offset(file_binary, path_file_dwarfs_aio, offset_end); @@ -210,7 +217,7 @@ void relocate(char** argv) // Create busybox symlinks, allow (symlinks exists) errors for(auto const& busybox_applet : arr_busybox_applet) { - fs::create_symlink(path_dir_app_bin / "busybox", path_dir_app_bin / busybox_applet, ec); + fs::create_symlink(path_dir_busybox / "busybox", path_dir_busybox / busybox_applet, ec); } // for // Filesystem starts here diff --git a/src/boot/config/config.hpp b/src/boot/config/config.hpp index 56892d9..f703dba 100644 --- a/src/boot/config/config.hpp +++ b/src/boot/config/config.hpp @@ -51,6 +51,7 @@ struct FlatimageConfig fs::path path_dir_mount; fs::path path_dir_app; fs::path path_dir_app_bin; + fs::path path_dir_busybox; fs::path path_dir_instance; fs::path path_file_binary; fs::path path_dir_binary; @@ -108,6 +109,7 @@ inline FlatimageConfig config() config.path_dir_binary = config.path_file_binary.parent_path(); config.path_dir_app = ns_env::get_or_throw("FIM_DIR_APP"); config.path_dir_app_bin = ns_env::get_or_throw("FIM_DIR_APP_BIN"); + config.path_dir_busybox = ns_env::get_or_throw("FIM_DIR_BUSYBOX"); config.path_dir_instance = ns_env::get_or_throw("FIM_DIR_INSTANCE"); config.path_dir_mount = ns_env::get_or_throw("FIM_DIR_MOUNT"); config.path_file_bashrc = config.path_dir_app / ".bashrc"; @@ -142,8 +144,9 @@ inline FlatimageConfig config() ns_env::set("BWRAP_LOG", config.path_dir_mount.string() + ".bwrap.log", ns_env::Replace::Y); // Environment - config.env_path = config.path_dir_app_bin.string() + ":" + ns_env::get_or_throw("PATH"); + config.env_path = config.path_dir_app_bin.string() + ":" + ns_env::get_or_else("PATH", ""); config.env_path += ":/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin"; + config.env_path += ":{}"_fmt(config.path_dir_busybox.string()); ns_env::set("PATH", config.env_path, ns_env::Replace::Y); // Compression level configuration (goes from 0 to 10, default is 7)