Skip to content

Commit 533ca8b

Browse files
Silic0nS0ldierSystemcluster
authored andcommitted
Use exec syscall on Unix, show forwarded args at max verbosity
1 parent 02fb3a0 commit 533ca8b

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

startpe/src/main.rs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ use std::{
88
time::SystemTime,
99
};
1010

11+
#[cfg(any(unix, target_os = "redox"))]
12+
use std::os::unix::process::CommandExt;
13+
1114
use memmap2::MmapOptions;
1215
use zerocopy::LayoutVerified;
1316

@@ -181,23 +184,36 @@ fn main() {
181184
println!("running...");
182185
}
183186

187+
let _ = mmap;
188+
184189
let args = std::env::args().skip(1).collect::<Vec<_>>();
190+
if show_information >= 2 {
191+
println!("forwarded args: {:?}", args);
192+
}
193+
185194
let mut command = Command::new(run_path);
186195
command.args(args);
187196
command.current_dir(current_dir);
188-
189-
let mut child = command
190-
.spawn()
191-
.unwrap_or_else(|e| panic!("failed to run {}: {}", run_path.display(), e));
192-
#[cfg(windows)]
193-
unsafe {
194-
if info.show_console == 0 {
195-
FreeConsole();
196-
}
197+
#[cfg(any(unix, target_os = "redox"))]
198+
{
199+
let e = command.exec();
200+
panic!("failed to run {}: {}", run_path.display(), e);
197201
}
198-
let result = child
199-
.wait()
200-
.unwrap_or_else(|e| panic!("failed to run {}: {}", run_path.display(), e));
202+
#[cfg(not(any(unix, target_os = "redox")))]
203+
{
204+
let mut child = command
205+
.spawn()
206+
.unwrap_or_else(|e| panic!("failed to run {}: {}", run_path.display(), e));
207+
#[cfg(windows)]
208+
unsafe {
209+
if info.show_console == 0 {
210+
FreeConsole();
211+
}
212+
}
213+
let result = child
214+
.wait()
215+
.unwrap_or_else(|e| panic!("failed to run {}: {}", run_path.display(), e));
201216

202-
std::process::exit(result.code().unwrap_or(0))
217+
std::process::exit(result.code().unwrap_or(0))
218+
}
203219
}

0 commit comments

Comments
 (0)