diff options
author | Profpatsch <mail@profpatsch.de> | 2021-02-06T21·23+0100 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2021-02-06T21·38+0000 |
commit | 7d28f121c7baba31f5bd731de8aff023fa23bdc0 (patch) | |
tree | 8224bf4fff1fc930a76432873a12daec14cda3fe /users/Profpatsch/execline/exec_helpers.rs | |
parent | 42974ddd6494097bf8a85a123b8637115977dda4 (diff) |
fix(users/Profpatsch/execline): fix exec_into_args off-by-1 r/2185
We expect the users to pass an actual prog, not an argv, so 0 is the program to exec into. Also improve the exec error, by including the program we tried to exec into (the rust IO error doesn’t contain the name). Change-Id: I664f9f717e4f82bfc1b1da3bd7114124b7582d5f Reviewed-on: https://cl.tvl.fyi/c/depot/+/2489 Reviewed-by: Profpatsch <mail@profpatsch.de> Tested-by: BuildkiteCI
Diffstat (limited to 'users/Profpatsch/execline/exec_helpers.rs')
-rw-r--r-- | users/Profpatsch/execline/exec_helpers.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/users/Profpatsch/execline/exec_helpers.rs b/users/Profpatsch/execline/exec_helpers.rs index 3e74ffc72210..9a67ffe45db5 100644 --- a/users/Profpatsch/execline/exec_helpers.rs +++ b/users/Profpatsch/execline/exec_helpers.rs @@ -31,12 +31,12 @@ pub fn exec_into_args<'a, 'b, Args, Arg, Env, Key, Val>(current_prog_name: &str, // TODO: is this possible without collecting into a Vec first, just leaving it an IntoIterator? let args = args.into_iter().collect::<Vec<Arg>>(); let mut args = args.iter().map(|v| OsStr::from_bytes(v.as_ref())); - let prog = args.nth(1).expect(&format!("{}: first argument must be an executable", current_prog_name)); + let prog = args.nth(0).expect(&format!("{}: first argument must be an executable", current_prog_name)); // TODO: same here let env = env_additions.into_iter().collect::<Vec<(Key, Val)>>(); let env = env.iter().map(|(k,v)| (OsStr::from_bytes(k.as_ref()), OsStr::from_bytes(v.as_ref()))); let err = std::process::Command::new(prog).args(args).envs(env).exec(); - die_missing_executable(current_prog_name, format!("exec failed: {:?}", err)); + die_missing_executable(current_prog_name, format!("exec failed: {}, while trying to execing into {:?}", err, prog)); } /// Exit 1 to signify a generic expected error |