diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-03-08 02:37:38 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-03-08 02:37:38 -0500 |
commit | 1abb97cca69e0b513f7499cc7db03ba622b38711 (patch) | |
tree | 6e59e0e7e4bfe9b00c735feb40c2286b3e0955c7 /src/info.rs | |
parent | d66f4773bccaee61c1c998640dcdb048223f8900 (diff) | |
download | nbsh-1abb97cca69e0b513f7499cc7db03ba622b38711.tar.gz nbsh-1abb97cca69e0b513f7499cc7db03ba622b38711.zip |
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
Diffstat (limited to 'src/info.rs')
-rw-r--r-- | src/info.rs | 11 |
1 files changed, 11 insertions, 0 deletions
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<std::path::PathBuf> { + Ok("/proc/self/exe".into()) +} + +#[cfg(not(target_os = "linux"))] +pub fn current_exe() -> Result<std::path::PathBuf> { + 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/: // |