Skip to content

Commit f998e27

Browse files
authored
Rollup merge of #68515 - Wind-River:master_2020, r=alexcrichton
Support feature process_set_argv0 for VxWorks r? @alexcrichton
2 parents b9c86a3 + 06af442 commit f998e27

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

src/libstd/sys/vxworks/ext/process.rs

+18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
#![stable(feature = "rust1", since = "1.0.0")]
44

5+
use crate::ffi::OsStr;
56
use crate::io;
67
use crate::process;
78
use crate::sys;
@@ -105,6 +106,15 @@ pub trait CommandExt {
105106
/// cross-platform `spawn` instead.
106107
#[stable(feature = "process_exec2", since = "1.9.0")]
107108
fn exec(&mut self) -> io::Error;
109+
110+
/// Set executable argument
111+
///
112+
/// Set the first process argument, `argv[0]`, to something other than the
113+
/// default executable path.
114+
#[unstable(feature = "process_set_argv0", issue = "66510")]
115+
fn arg0<S>(&mut self, arg: S) -> &mut process::Command
116+
where
117+
S: AsRef<OsStr>;
108118
}
109119

110120
#[stable(feature = "rust1", since = "1.0.0")]
@@ -130,6 +140,14 @@ impl CommandExt for process::Command {
130140
fn exec(&mut self) -> io::Error {
131141
self.as_inner_mut().exec(sys::process::Stdio::Inherit)
132142
}
143+
144+
fn arg0<S>(&mut self, arg: S) -> &mut process::Command
145+
where
146+
S: AsRef<OsStr>,
147+
{
148+
self.as_inner_mut().set_arg_0(arg.as_ref());
149+
self
150+
}
133151
}
134152

135153
/// Unix-specific extensions to [`process::ExitStatus`].

src/libstd/sys/vxworks/process/process_common.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ impl Command {
9090
let program = os2c(program, &mut saw_nul);
9191
Command {
9292
argv: Argv(vec![program.as_ptr(), ptr::null()]),
93+
args: vec![program.clone()],
9394
program,
94-
args: Vec::new(),
9595
env: Default::default(),
9696
cwd: None,
9797
uid: None,
@@ -104,11 +104,19 @@ impl Command {
104104
}
105105
}
106106

107+
pub fn set_arg_0(&mut self, arg: &OsStr) {
108+
// Set a new arg0
109+
let arg = os2c(arg, &mut self.saw_nul);
110+
debug_assert!(self.argv.0.len() > 1);
111+
self.argv.0[0] = arg.as_ptr();
112+
self.args[0] = arg;
113+
}
114+
107115
pub fn arg(&mut self, arg: &OsStr) {
108116
// Overwrite the trailing NULL pointer in `argv` and then add a new null
109117
// pointer.
110118
let arg = os2c(arg, &mut self.saw_nul);
111-
self.argv.0[self.args.len() + 1] = arg.as_ptr();
119+
self.argv.0[self.args.len()] = arg.as_ptr();
112120
self.argv.0.push(ptr::null());
113121

114122
// Also make sure we keep track of the owned value to schedule a
@@ -133,6 +141,10 @@ impl Command {
133141
&self.argv.0
134142
}
135143

144+
pub fn get_program(&self) -> &CStr {
145+
&*self.program
146+
}
147+
136148
#[allow(dead_code)]
137149
pub fn get_cwd(&self) -> &Option<CString> {
138150
&self.cwd
@@ -315,8 +327,12 @@ impl ChildStdio {
315327

316328
impl fmt::Debug for Command {
317329
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
318-
write!(f, "{:?}", self.program)?;
319-
for arg in &self.args {
330+
if self.program != self.args[0] {
331+
write!(f, "[{:?}] ", self.program)?;
332+
}
333+
write!(f, "{:?}", self.args[0])?;
334+
335+
for arg in &self.args[1..] {
320336
write!(f, " {:?}", arg)?;
321337
}
322338
Ok(())

src/libstd/sys/vxworks/process/process_vxworks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl Command {
6767
let _lock = sys::os::env_lock();
6868

6969
let ret = libc::rtpSpawn(
70-
self.get_argv()[0], // executing program
70+
self.get_program().as_ptr(),
7171
self.get_argv().as_ptr() as *mut *const c_char, // argv
7272
c_envp as *mut *const c_char,
7373
100 as c_int, // initial priority

0 commit comments

Comments
 (0)