summaryrefslogtreecommitdiff
path: root/makima/src/daemon/process
diff options
context:
space:
mode:
authorsoryu <soryu@soryu.co>2026-01-15 03:39:16 +0000
committersoryu <soryu@soryu.co>2026-01-15 03:39:28 +0000
commit3fe9a6c6b113d64c7a8409b5463026700be4c28c (patch)
tree5f17c31fe3e0036b75b6ad40a2748751fd678b5c /makima/src/daemon/process
parent764bd28d08ceaef03cd4050f9568a62d77bbcfca (diff)
downloadsoryu-3fe9a6c6b113d64c7a8409b5463026700be4c28c.tar.gz
soryu-3fe9a6c6b113d64c7a8409b5463026700be4c28c.zip
Add cleanup to daemon
Also fixup for container image
Diffstat (limited to 'makima/src/daemon/process')
-rw-r--r--makima/src/daemon/process/claude.rs35
1 files changed, 34 insertions, 1 deletions
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<u32> {
+ 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<bool, ClaudeProcessError> {
+ 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<bool, ClaudeProcessError> {
+ // 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<OutputLine> {
self.output_rx.recv().await