{"record":{"id":"b3b8739cc3e34f3e","repo":"rustdesk/rustdesk","slug":"failed-to-resolve-current-executable-path","errorCode":null,"errorMessage":"Failed to resolve current executable path: {}","messagePattern":"Failed to resolve current executable path: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ipc/auth.rs","lineNumber":293,"sourceCode":"            fd,\n            libc::SOL_SOCKET,\n            libc::SO_PEERCRED,\n            &mut cred as *mut _ as *mut libc::c_void,\n            &mut len,\n        )\n    };\n    if rc == 0 {\n        Some(cred)\n    } else {\n        None\n    }\n}\n\n#[cfg(any(target_os = \"linux\", target_os = \"macos\", target_os = \"windows\"))]\n#[inline]\nfn current_exe_canonical_path() -> ResultType<PathBuf> {\n    let current = std::env::current_exe()\n        .map_err(|err| anyhow::anyhow!(\"Failed to resolve current executable path: {}\", err))?;\n    fs::canonicalize(&current).map_err(|err| {\n        anyhow::anyhow!(\n            \"Failed to canonicalize current executable path '{}': {}\",\n            current.display(),\n            err\n        )\n        .into()\n    })\n}\n\n#[cfg(target_os = \"linux\")]\n#[inline]\nfn peer_exe_canonical_path_by_pid(peer_pid: u32) -> ResultType<PathBuf> {\n    let proc_exe = PathBuf::from(format!(\"/proc/{peer_pid}/exe\"));\n    let peer_exe = fs::read_link(&proc_exe).map_err(|err| {\n        anyhow::anyhow!(\n            \"Failed to read peer executable link '{}': {}\",\n            proc_exe.display(),","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/rustdesk/rustdesk/blob/91c9fccbb0f7bfe5f11644d5fbdec9b23fa10540/src/ipc/auth.rs#L275-L311","documentation":"current_exe_canonical_path resolves the current process executable via std::env::current_exe() and then canonicalizes it. This error wraps a failure of current_exe() itself into an anyhow error; callers use the result to verify that a peer IPC process (portable service / logon helper) is the expected executable.","triggerScenarios":"Calling windows_portable_service_ipc_allows_logon_helper_executable or ensure_peer_executable_matches_current_by_pid when std::env::current_exe() fails - e.g. the executable path cannot be determined by the OS, the binary was deleted/renamed while running, or /proc self-exe resolution fails on Linux.","commonSituations":"Binary deleted or replaced after launch (update-in-place) while the process still runs; running under an environment where the executable image cannot be queried; heavily sandboxed runtime deleting its own image.","solutions":["Ensure the running executable file is not deleted/renamed in place; use atomic install (write new file, rename over old) for updates.","Reproduce the raw std::env::current_exe() error and fix the launch environment (check /proc/self/exe on Linux, GetModuleFileName on Windows).","Cache the canonical exe path at process start before any update procedure can touch the binary.","If verification of a peer is failing, also check the peer's PID is still alive - the same helper reports peer-path errors."],"exampleFix":"// before\nlet current = std::env::current_exe()\n    .map_err(|err| anyhow::anyhow!(\"Failed to resolve current executable path: {}\", err))?;\n// after (fail fast at startup, before peers are spawned)\nlet exe_path = std::env::current_exe()\n    .map_err(|err| anyhow::anyhow!(\"Failed to resolve current executable path: {}\", err))?;\nlet exe_path = fs::canonicalize(&exe_path)?; // done once in main, reused for peer verification","handlingStrategy":"fallback","validationCode":"fn exe_path_available() -> bool {\n    std::env::current_exe().is_ok()\n}","typeGuard":null,"tryCatchPattern":"match current_exe_canonical_path() {\n    Ok(p) => verify_peer_against(p),\n    Err(e) => {\n        log::error!(\"cannot verify peer executable: {e}; denying IPC connection\");\n        // fail closed: treat verification as failed rather than allowing\n    }\n}","preventionTips":["Use atomic updates (rename over) so the running executable file is never deleted in place.","Resolve and cache the canonical exe path once at process start.","Keep peer-verification fail-closed: a resolution error should deny, not allow, the IPC peer."],"tags":["filesystem","executable-path","process"],"backgroundTag":"file-not-found","analyzedSha":"91c9fccbb0f7bfe5f11644d5fbdec9b23fa10540","analyzedAt":"2026-09-10T19:53:44.083Z","contentChangedAt":"2026-09-10T19:53:44.083Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}