提交 8b3c047e authored 作者: Serhij S's avatar Serhij S

handle deleted exe

上级 4a62b1da
......@@ -367,9 +367,16 @@ pub fn configure_logger(filter: LevelFilter) {
/// Reload the current executable (performs execvp syscall, Linux only)
#[cfg(target_os = "linux")]
pub fn reload_executable() -> Result<()> {
std::os::unix::process::CommandExt::exec(&mut std::process::Command::new(
std::env::current_exe()?,
));
let mut current_exe = std::env::current_exe()?;
// handle a case if the executable is deleted
let fname = current_exe
.file_name()
.ok_or_else(|| Error::Failed("No file name".to_owned()))?
.to_string_lossy()
.trim_end_matches(" (deleted)")
.to_owned();
current_exe = current_exe.with_file_name(fname);
std::os::unix::process::CommandExt::exec(&mut std::process::Command::new(current_exe));
Ok(())
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论