Skip to content

Commit dae7bef

Browse files
committed
runcon: use Command::exec() instead of libc::execvp()
No need to use the libc crate for execvp, the standard rust library provides the functionality via `Command::exec()`. Signed-off-by: Etienne Cordonnier <[email protected]>
1 parent aaa0610 commit dae7bef

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

src/uu/runcon/src/runcon.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ use uucore::format_usage;
1515

1616
use std::borrow::Cow;
1717
use std::ffi::{CStr, CString, OsStr, OsString};
18-
use std::os::raw::c_char;
18+
use std::io;
1919
use std::os::unix::ffi::OsStrExt;
20-
use std::{io, ptr};
20+
use std::os::unix::process::CommandExt;
21+
use std::process;
2122

2223
mod errors;
2324

@@ -367,23 +368,8 @@ fn get_custom_context(
367368
/// compiler the only valid return type is to say "if this returns, it will
368369
/// always return an error".
369370
fn execute_command(command: &OsStr, arguments: &[OsString]) -> UResult<()> {
370-
let c_command = os_str_to_c_string(command).map_err(RunconError::new)?;
371+
let err = process::Command::new(command).args(arguments).exec();
371372

372-
let argv_storage: Vec<CString> = arguments
373-
.iter()
374-
.map(AsRef::as_ref)
375-
.map(os_str_to_c_string)
376-
.collect::<Result<_>>()
377-
.map_err(RunconError::new)?;
378-
379-
let mut argv: Vec<*const c_char> = Vec::with_capacity(arguments.len().saturating_add(2));
380-
argv.push(c_command.as_ptr());
381-
argv.extend(argv_storage.iter().map(AsRef::as_ref).map(CStr::as_ptr));
382-
argv.push(ptr::null());
383-
384-
unsafe { libc::execvp(c_command.as_ptr(), argv.as_ptr()) };
385-
386-
let err = io::Error::last_os_error();
387373
let exit_status = if err.kind() == io::ErrorKind::NotFound {
388374
error_exit_status::NOT_FOUND
389375
} else {

0 commit comments

Comments
 (0)