From 1abb97cca69e0b513f7499cc7db03ba622b38711 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 8 Mar 2022 02:37:38 -0500 Subject: use /proc/self/exe directly when re-execing ourself when possible this will use the same binary that is currently running, even if it has been deleted or replaced --- src/info.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/info.rs') diff --git a/src/info.rs b/src/info.rs index dc62125..6a5ad4f 100644 --- a/src/info.rs +++ b/src/info.rs @@ -35,6 +35,17 @@ pub fn pid() -> String { nix::unistd::getpid().to_string() } +#[cfg(target_os = "linux")] +#[allow(clippy::unnecessary_wraps)] +pub fn current_exe() -> Result { + Ok("/proc/self/exe".into()) +} + +#[cfg(not(target_os = "linux"))] +pub fn current_exe() -> Result { + Ok(std::env::current_exe()?) +} + // the time crate is currently unable to get the local offset on unix due to // soundness concerns, so we have to do it manually/: // -- cgit v1.2.3-54-g00ecf