Skip to content

Commit b0d4723

Browse files
committed
v0.0.3
1 parent d2739c8 commit b0d4723

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/main.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// #![windows_subsystem = "windows"]
22

33
use std::env;
4+
use std::fs::read;
45
use std::path::PathBuf;
56
use std::process::exit;
67
use std::io::{self, IsTerminal, Read};
@@ -94,16 +95,16 @@ fn main() {
9495
}
9596
}
9697

98+
if !file_path.to_str().unwrap().is_empty() && exec_file.is_empty() {
99+
exec_file = read(&file_path).unwrap()
100+
}
101+
97102
#[cfg(target_os = "windows")]
98103
{
99104
use std::io::Write;
100105
use std::process::{Stdio, Command};
101106

102-
if !_is_child && (!file_path.to_str().unwrap().is_empty() || args.url.is_some() || args.stdin) {
103-
if !file_path.to_str().unwrap().is_empty() && exec_file.is_empty() {
104-
exec_file = std::fs::read(file_path).unwrap()
105-
}
106-
107+
if !_is_child && (!exec_file.is_empty() || args.stdin) {
107108
env::set_var("ULEXEC_CHILD", "1");
108109
let mut child = Command::new(env::current_exe().unwrap())
109110
.args(args.exec_args)
@@ -125,7 +126,6 @@ fn main() {
125126

126127
#[cfg(target_os = "linux")]
127128
{
128-
use std::fs::File;
129129
use std::ffi::CString;
130130
use std::thread::spawn;
131131
use std::os::fd::AsRawFd;
@@ -143,11 +143,6 @@ fn main() {
143143
.p_vaddr == 0
144144
}
145145

146-
if exec_file.is_empty() {
147-
let mut file = File::open(file_path.clone()).unwrap();
148-
file.read_to_end(&mut exec_file).unwrap();
149-
}
150-
151146
if !is_pie(&exec_file) {
152147
exit(MemFdExecutable::new("exec", &exec_file)
153148
.args(args.exec_args)
@@ -171,7 +166,7 @@ fn main() {
171166
).unwrap();
172167
let memfd_raw = memfd.as_raw_fd();
173168

174-
if file_path.to_str().unwrap().is_empty() {
169+
if file_path.to_str().unwrap().is_empty() && !exec_file.is_empty() {
175170
write(memfd, &exec_file).unwrap();
176171
file_path = PathBuf::from(
177172
format!("/proc/self/fd/{}", memfd_raw.to_string())

0 commit comments

Comments
 (0)