Skip to content

Commit

Permalink
Modify permissions of linux executable before running it
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanformigoni committed Oct 26, 2024
1 parent f193382 commit e8be68c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/boot/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,24 @@ void boot_linux(ns_db::ns_project::Project& db_project, fs::path const& path_dir
// Enter application directory
fs::current_path(path_dir_self);

// Escape "'"
std::string cmd = ns_string::replace_substrings((path_dir_self / db_project.path_file_rom).c_str(), "'", R"('\'')");

// Sorround with ''
cmd = fmt::format(fmt::runtime("'{}'"), cmd);
// Create full path to rom
fs::path path_file_rom = path_dir_self / db_project.path_file_rom;

// Include exec and read permissions (allow to fail)
lec(fs::permissions, path_file_rom
, fs::perms::owner_exec | fs::perms::group_exec | fs::perms::others_exec
| fs::perms::owner_read | fs::perms::group_read | fs::perms::others_read
, fs::perm_options::add
);

// Start application
ns_log::write('i', "Execute: ", cmd);
ns_log::write('i', "Execute: ", path_file_rom);

auto optional_path_file_bash = ns_subprocess::search_path("bash");
ereturn_if (not optional_path_file_bash, "Could not find bash");
(void) ns_subprocess::Subprocess(*optional_path_file_bash)
.with_piped_outputs()
.with_args("-c", cmd)
.with_args("-c", R"("{}" "$@")"_fmt(path_file_rom))
.spawn()
.wait();
} // boot_linux() }}}
Expand Down

0 comments on commit e8be68c

Please sign in to comment.