tui: spawn the wallet-rpc binary that sits next to the app
All checks were successful
ci / test (pull_request) Successful in 14m27s
ci / sdk (pull_request) Successful in 1m26s

A bare monero-wallet-rpc name is the executable beside this binary
when that file is executable, then PATH. An absolute path is left
alone, so Android and operator overrides keep working. Remote daemon
and remote wallet RPC are unchanged.
This commit is contained in:
agent 2026-10-11 19:41:11 -04:00
commit 37690e3d48
No known key found for this signature in database
4 changed files with 139 additions and 2 deletions

View file

@ -603,8 +603,11 @@ impl WalletChild {
let port = Self::pick_port()?;
let login = format!("{user}:{}", pass.as_str());
let daemon = Self::daemon_address(&self.source);
// A bare name is the copy next to this binary, when one is there.
// An absolute path is the caller's (Android jniLibs, a test fake).
let bin = resolve_wallet_rpc_bin(&self.wallet_rpc_bin, bundled_wallet_rpc_dir().as_deref());
let argv = Self::wallet_rpc_argv(
&self.wallet_rpc_bin,
&bin,
port,
&login,
&self.wallet_dir,
@ -1206,6 +1209,39 @@ fn source_from_json(value: &serde_json::Value) -> Result<ChainSource> {
}
}
/// A bare wallet-rpc name is the copy sitting next to this binary, when that
/// file is executable. An absolute or relative path is the caller's binary
/// (Android's jniLibs entry, a test fake, a path the operator typed) and is
/// not rewritten. No executable sibling leaves the bare name, which `Command`
/// resolves on `PATH`.
fn resolve_wallet_rpc_bin(configured: &Path, beside: Option<&Path>) -> PathBuf {
if configured.components().nth(1).is_some() {
return configured.to_path_buf();
}
let Some(dir) = beside else {
return configured.to_path_buf();
};
let candidate = dir.join(configured);
if executable_file(&candidate) {
candidate
} else {
configured.to_path_buf()
}
}
fn executable_file(path: &Path) -> bool {
std::fs::metadata(path)
.is_ok_and(|meta| meta.is_file() && meta.permissions().mode() & 0o111 != 0)
}
/// Directory of the running executable. `None` if the process cannot name
/// itself — the bare name then stays on `PATH`.
fn bundled_wallet_rpc_dir() -> Option<PathBuf> {
std::env::current_exe()
.ok()
.and_then(|exe| exe.parent().map(|dir| dir.to_path_buf()))
}
fn spawn(argv: &[String], what: &str) -> Result<Child> {
let (bin, args) = argv
.split_first()
@ -1831,6 +1867,51 @@ mod tests {
);
}
/// A bare name is the bundled binary sitting next to the app. An absolute
/// path (Android's jniLibs entry, a test fake, a path the operator typed)
/// is not rewritten. No executable sibling leaves the bare name for `PATH`.
#[test]
fn a_bare_wallet_rpc_name_uses_the_executable_beside_the_app() {
let dir = tmp_dir("bundled-rpc");
std::fs::create_dir_all(&dir).unwrap();
let sibling = dir.join("monero-wallet-rpc");
std::fs::write(&sibling, b"#!/bin/sh\n").unwrap();
let mut perms = std::fs::metadata(&sibling).unwrap().permissions();
perms.set_mode(0o755);
std::fs::set_permissions(&sibling, perms).unwrap();
assert_eq!(
resolve_wallet_rpc_bin(Path::new("monero-wallet-rpc"), Some(&dir)),
sibling
);
let configured = PathBuf::from("/opt/monero/monero-wallet-rpc");
assert_eq!(
resolve_wallet_rpc_bin(&configured, Some(&dir)),
configured,
"an absolute path is the operator's binary, not the sibling"
);
let empty = tmp_dir("bundled-rpc-miss");
std::fs::create_dir_all(&empty).unwrap();
assert_eq!(
resolve_wallet_rpc_bin(Path::new("monero-wallet-rpc"), Some(&empty)),
PathBuf::from("monero-wallet-rpc"),
"no sibling means PATH"
);
let blocked = empty.join("monero-wallet-rpc");
std::fs::write(&blocked, b"no").unwrap();
let mut perms = std::fs::metadata(&blocked).unwrap().permissions();
perms.set_mode(0o644);
std::fs::set_permissions(&blocked, perms).unwrap();
assert_eq!(
resolve_wallet_rpc_bin(Path::new("monero-wallet-rpc"), Some(&empty)),
PathBuf::from("monero-wallet-rpc"),
"a non-executable sibling is not the bundled binary"
);
}
#[test]
fn monerod_argv_binds_loopback_and_uses_the_datadir() {
let dir = tmp_dir("monerod-argv");