Skip to content

Commit 7345eec

Browse files
Avoid repeating original argv[0]
resolves #6 binfmt-dispatcher gets typically registered to binfmt-misc with flags `POCF`. - `P` will preserve the original argv[0] used - `O` will give the resolved binary (e.g. after symlink derefence) as an open file in fd 3 - but we can't use it as-is as FEX (at least) doesn't support taking "pathname" (execve) as an open file descriptor. - `C` and `F` are irrelevant here. To support properly binary file already open as fd 3, FEX needs to be patched to use `fexecve(3, argv, env)` kind of call when requested, it doesn't appear to support it yet. Signed-off-by: Fabrice A. Marie <[email protected]>
1 parent c195c9e commit 7345eec

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

src/main.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn main() {
4242
trace!("Configuration:\n{:#?}", settings);
4343

4444
// Collect command line arguments to pass through
45-
let args: Vec<OsString> = env::args_os().skip(1).collect();
45+
let mut args: Vec<OsString> = env::args_os().skip(1).collect();
4646
trace!("Args:\n{:#?}", args);
4747
if args.is_empty() {
4848
abort("No arguments passed, re-run with --help to learn more.");
@@ -60,13 +60,6 @@ fn main() {
6060
}
6161
}
6262

63-
// File descriptor 3 is where binfmt_misc typically passes the executable
64-
let binary: PathBuf = read_link("/proc/self/fd/3").unwrap_or_else(|e| {
65-
error!("Failed to read the executable from fd#3: {}", e);
66-
exit(1);
67-
});
68-
trace!("Binary: {:#?}", binary);
69-
7063
let mut interpreter_id = &settings.defaults.interpreter;
7164
for binary in settings.binaries.values() {
7265
if Path::new(&binary.path) == canonicalize(&args[0]).unwrap() {
@@ -156,8 +149,9 @@ fn main() {
156149
command = Command::new(interpreter_path);
157150
}
158151

159-
command.arg(binary);
160-
152+
let new_binary = args.remove(0);
153+
args.remove(0);
154+
command.arg(new_binary);
161155
// Pass through all the arguments
162156
command.args(&args);
163157

0 commit comments

Comments
 (0)