1
0
mirror of https://github.com/containers/youki synced 2024-11-23 01:11:58 +01:00

Add resolution of runtime path using which crate

Now it is not required to give complete path of the runtime, if it exists in $PATH
previously needed to provide /usr/bin/run, now only runc resolves to it
This commit is contained in:
Yashodhan Joshi 2021-09-20 20:48:10 +05:30
parent 5e07e90e18
commit 28ce007066
3 changed files with 32 additions and 3 deletions

@ -137,6 +137,12 @@ dependencies = [
"syn",
]
[[package]]
name = "either"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
name = "filetime"
version = "0.2.15"
@ -514,6 +520,17 @@ version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "which"
version = "4.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea187a8ef279bc014ec368c27a920da2024d2a711109bfbe3440585d5cf27ad9"
dependencies = [
"either",
"lazy_static",
"libc",
]
[[package]]
name = "winapi"
version = "0.3.9"
@ -560,4 +577,5 @@ dependencies = [
"tar",
"test_framework",
"uuid",
"which",
]

@ -21,4 +21,5 @@ test_framework = { version = "0.1.0", path = "../test_framework"}
anyhow = "1.0"
lazy_static = "1.4.0"
once_cell = "1.8.0"
oci-spec = "0.5.1"
oci-spec = "0.5.1"
which = "4.2.2"

@ -39,8 +39,18 @@ fn parse_tests(tests: &[String]) -> Vec<(&str, Option<Vec<&str>>)> {
fn main() -> Result<()> {
let opts: Opts = Opts::parse();
let path = std::fs::canonicalize(opts.runtime).expect("Invalid runtime path");
set_runtime_path(&path);
match std::fs::canonicalize(opts.runtime.clone()) {
// runtime path is relative or resolved correctly
Ok(path) => set_runtime_path(&path),
// runtime path is name of program which probably exists in $PATH
Err(_) => match which::which(opts.runtime) {
Ok(path) => set_runtime_path(&path),
Err(e) => {
eprintln!("Error in finding runtime : {}\nexiting.", e);
std::process::exit(66);
}
},
}
let mut tm = TestManager::new();