diff --git a/src/exec.rs b/src/exec.rs index ff368523a..638f523c0 100644 --- a/src/exec.rs +++ b/src/exec.rs @@ -421,7 +421,7 @@ fn safe_launch_process( } set_errno(err); - safe_report_exec_error(errno().0, actual_cmd.as_ptr(), argv.get(), envv.get()); + safe_report_exec_error(errno().0, actual_cmd, argv.get(), envv.get()); exit_without_destructors(exit_code_from_exec_error(err.0)); } @@ -721,8 +721,8 @@ fn fork_child_for_process( p.pid(), pgid, job.job_id().as_num(), - narrow_cmd.as_ptr(), - narrow_argv0.as_ptr(), + &narrow_cmd, + &narrow_argv0, ) } } @@ -858,7 +858,7 @@ fn exec_external_command( let pid = match pid { Ok(pid) => pid, Err(err) => { - safe_report_exec_error(err.0, actual_cmd.as_ptr(), argv.get(), envv.get()); + safe_report_exec_error(err.0, &actual_cmd, argv.get(), envv.get()); p.status .update(&ProcStatus::from_exit_code(exit_code_from_exec_error( err.0, diff --git a/src/fork_exec/postfork.rs b/src/fork_exec/postfork.rs index 96e8a097f..f27d53033 100644 --- a/src/fork_exec/postfork.rs +++ b/src/fork_exec/postfork.rs @@ -52,17 +52,11 @@ pub(crate) fn report_setpgid_error( pid: pid_t, desired_pgid: pid_t, job_id: i64, - command_str: *const c_char, - argv0_str: *const c_char, + command: &CStr, + argv0: &CStr, ) { let cur_group = unsafe { libc::getpgid(pid) }; - // TODO: command_str ought to be passed as a CStr. - // This is worth fixing as CStr::from_ptr may invoke libc strlen() which - // is not async signal safe on old versions of POSIX. - let command: &CStr = unsafe { CStr::from_ptr(command_str) }; - let argv0: &CStr = unsafe { CStr::from_ptr(argv0_str) }; - FLOG_SAFE!( warning, "Could not send ", @@ -245,12 +239,10 @@ pub fn execute_fork() -> pid_t { pub(crate) fn safe_report_exec_error( err: i32, - actual_cmd: *const c_char, + actual_cmd: &CStr, argvv: *const *const c_char, envv: *const *const c_char, ) { - // TODO: actual_cmd may be passed as a CStr. - let actual_cmd: &CStr = unsafe { CStr::from_ptr(actual_cmd) }; match err { libc::E2BIG => { let mut sz = 0;