|
3 | 3 | // For the full copyright and license information, please view the LICENSE |
4 | 4 | // file that was distributed with this source code. |
5 | 5 |
|
6 | | -// spell-checker:ignore (ToDO) execvp SIGHUP cproc vprocmgr cstrs homeout |
| 6 | +// spell-checker:ignore (ToDO) SIGHUP cproc vprocmgr homeout |
7 | 7 |
|
8 | 8 | use clap::{Arg, ArgAction, Command}; |
9 | | -use libc::{SIG_IGN, SIGHUP}; |
10 | | -use libc::{c_char, dup2, execvp, signal}; |
| 9 | +use libc::{SIG_IGN, SIGHUP, dup2, signal}; |
11 | 10 | use std::env; |
12 | | -use std::ffi::CString; |
13 | 11 | use std::fs::{File, OpenOptions}; |
14 | | -use std::io::{Error, IsTerminal}; |
| 12 | +use std::io::{Error, ErrorKind, IsTerminal}; |
15 | 13 | use std::os::unix::prelude::*; |
| 14 | +use std::os::unix::process::CommandExt; |
16 | 15 | use std::path::{Path, PathBuf}; |
| 16 | +use std::process; |
17 | 17 | use thiserror::Error; |
18 | 18 | use uucore::display::Quotable; |
19 | 19 | use uucore::error::{UError, UResult, set_exit_code}; |
@@ -68,17 +68,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { |
68 | 68 | return Err(NohupError::CannotDetach.into()); |
69 | 69 | } |
70 | 70 |
|
71 | | - let cstrs: Vec<CString> = matches |
72 | | - .get_many::<String>(options::CMD) |
73 | | - .unwrap() |
74 | | - .map(|x| CString::new(x.as_bytes()).unwrap()) |
75 | | - .collect(); |
76 | | - let mut args: Vec<*const c_char> = cstrs.iter().map(|s| s.as_ptr()).collect(); |
77 | | - args.push(std::ptr::null()); |
78 | | - |
79 | | - let ret = unsafe { execvp(args[0], args.as_mut_ptr()) }; |
80 | | - match ret { |
81 | | - libc::ENOENT => set_exit_code(EXIT_ENOENT), |
| 71 | + let mut cmd_iter = matches.get_many::<String>(options::CMD).unwrap(); |
| 72 | + let cmd = cmd_iter.next().unwrap(); |
| 73 | + let args: Vec<&String> = cmd_iter.collect(); |
| 74 | + |
| 75 | + let err = process::Command::new(cmd).args(args).exec(); |
| 76 | + |
| 77 | + match err.kind() { |
| 78 | + ErrorKind::NotFound => set_exit_code(EXIT_ENOENT), |
82 | 79 | _ => set_exit_code(EXIT_CANNOT_INVOKE), |
83 | 80 | } |
84 | 81 | Ok(()) |
|
0 commit comments