From 3fe9a6c6b113d64c7a8409b5463026700be4c28c Mon Sep 17 00:00:00 2001 From: soryu Date: Thu, 15 Jan 2026 03:39:16 +0000 Subject: Add cleanup to daemon Also fixup for container image --- makima/src/daemon/process/claude.rs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'makima/src/daemon/process/claude.rs') diff --git a/makima/src/daemon/process/claude.rs b/makima/src/daemon/process/claude.rs index 93b097c..536d883 100644 --- a/makima/src/daemon/process/claude.rs +++ b/makima/src/daemon/process/claude.rs @@ -102,12 +102,45 @@ impl ClaudeProcess { } } - /// Kill the process. + /// Kill the process (SIGKILL). pub async fn kill(&mut self) -> Result<(), ClaudeProcessError> { self.child.kill().await?; Ok(()) } + /// Get the process ID, if the process is still running. + pub fn id(&self) -> Option { + self.child.id() + } + + /// Send SIGTERM to gracefully terminate the process (Unix only). + /// Returns Ok(true) if signal was sent, Ok(false) if process already exited. + #[cfg(unix)] + pub fn terminate(&self) -> Result { + use nix::sys::signal::{kill, Signal}; + use nix::unistd::Pid; + + if let Some(pid) = self.child.id() { + match kill(Pid::from_raw(pid as i32), Signal::SIGTERM) { + Ok(()) => Ok(true), + Err(nix::errno::Errno::ESRCH) => Ok(false), // Process doesn't exist + Err(e) => Err(ClaudeProcessError::OutputRead(format!( + "Failed to send SIGTERM: {}", + e + ))), + } + } else { + Ok(false) // Process already exited + } + } + + /// Send SIGTERM to gracefully terminate the process (no-op on non-Unix). + #[cfg(not(unix))] + pub fn terminate(&self) -> Result { + // On non-Unix platforms, fall back to kill + Ok(false) + } + /// Get the next output line, if available. pub async fn next_output(&mut self) -> Option { self.output_rx.recv().await -- cgit v1.2.3