mirror of
https://github.com/DaLaw2/NetGuardia.git
synced 2026-08-24 14:10:28 +09:00
fix: restart uses exec to re-launch process instead of exit(0)
Previous implementation relied on systemd Restart=always to restart the process after exit(0), which meant restart was identical to shutdown without systemd. Now uses std::process::Command::exec() (Unix execvp) to replace the current process image with a fresh instance. Works with or without systemd. system.terminate() is called first to detach eBPF and stop ML engine before exec. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c2e1aff12d
commit
7b2b4f1f1e
@ -107,8 +107,15 @@ async fn main() -> Result<(), Error> {
|
||||
crate::core::system::ShutdownMode::Restart => {
|
||||
log!(SystemLog::ApiRestart);
|
||||
let _ = sd_notify::notify(false, &[sd_notify::NotifyState::Reloading]);
|
||||
// Exit with 0 — systemd Restart=always will restart the process
|
||||
std::process::exit(0);
|
||||
// Re-exec self — works with or without systemd
|
||||
use std::os::unix::process::CommandExt;
|
||||
let exe = std::env::current_exe().unwrap_or_else(|_| std::path::PathBuf::from("net-guardia"));
|
||||
let err = std::process::Command::new(exe)
|
||||
.args(std::env::args().skip(1))
|
||||
.exec(); // replaces current process
|
||||
// If exec fails, fall through to exit
|
||||
log!(SystemError::UnexpectedError(err));
|
||||
std::process::exit(1);
|
||||
}
|
||||
crate::core::system::ShutdownMode::Shutdown => {
|
||||
log!(SystemLog::ApiShutdown);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user