From 3f3d176e2d3960b9c18589e64af2fbe9de435f0d Mon Sep 17 00:00:00 2001 From: "A. Wilcox" <AWilcox@Wilcox-Tech.com> Date: Fri, 17 Nov 2023 21:51:32 -0600 Subject: Executor: Only stack runlevels if runlevels exist If we are doing a mini-rootfs or container installation, we may not have OpenRC at all. This would mean /etc/runlevels doesn't exist in the target. In that case, we crash with: boost::filesystem::directory_iterator::construct: No such file or directory [system:2]: "/tmp/horizon-image/target/etc/runlevels" Closes: #378 Fixes: a9ccd9bc7e ("hscript: Allow svcenable to create new runlevels") --- hscript/script_e.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hscript/script_e.cc b/hscript/script_e.cc index 8f0f4b4..50f92e1 100644 --- a/hscript/script_e.cc +++ b/hscript/script_e.cc @@ -678,14 +678,14 @@ bool Script::execute() const { EXECUTE_OR_FAIL("svcenable", svc) } #ifdef HAS_INSTALL_ENV - if(!opts.test(Simulate)) { - const std::set<std::string> def_runlevels{ + if(!opts.test(Simulate) && fs::exists(targ_etc + "/runlevels", ec)) { + const std::set<std::string> def_runlevels{ "boot", "default", "empty", "nonetwork", "shutdown", "sysinit" }; - const auto rl_dir{targ_etc + "/runlevels"}; + const auto rl_dir{targ_etc + "/runlevels"}; for(auto &&file : fs::directory_iterator(rl_dir)) { const auto runlevel{file.path().filename().string()}; - if(def_runlevels.find(runlevel) == def_runlevels.end()) { + if(def_runlevels.find(runlevel) == def_runlevels.end()) { fs::create_symlink("../default", rl_dir + "/" + runlevel + "/default", ec); if(ec) { -- cgit v1.2.3-70-g09d2