Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Dec 13, 2024
1 parent aec7af1 commit b202e91
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/cli/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl Logs {

fn print_existing_logs(&self) -> Result<()> {
let log_files = get_log_file_infos(&self.id)?;
trace!("log files for: {}", log_files.keys().join(", "));
let log_lines = log_files
.iter()
.flat_map(|(name, lf)| {
Expand All @@ -77,7 +78,7 @@ impl Logs {
let log_lines = if self.n == 0 {
log_lines.collect_vec()
} else {
log_lines.take(self.n).collect_vec()
log_lines.rev().take(self.n).rev().collect_vec()
};

for (date, id, msg) in log_lines {
Expand Down
15 changes: 15 additions & 0 deletions src/procs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ impl Procs {
.is_some()
}

pub fn all_children(&self, pid: u32) -> Vec<u32> {
let system = self.system.lock().unwrap();
let all = system.processes();
let mut children = vec![];
for (child_pid, process) in all {
while let Some(parent) = process.parent() {
if parent == sysinfo::Pid::from_u32(pid) {
children.push(child_pid.as_u32());
break;
}
}
}
children
}

pub async fn kill_async(&self, pid: u32) -> Result<bool> {
let result = tokio::task::spawn_blocking(move || PROCS.kill(pid))
.await
Expand Down
5 changes: 5 additions & 0 deletions src/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ impl Supervisor {
})
.await?;
PROCS.kill_async(pid).await?;
PROCS.refresh_processes();
for pid in PROCS.all_children(pid) {
debug!("killing child pid: {pid}");
PROCS.kill_async(pid).await?;
}
} else {
debug!("pid {pid} not running");
}
Expand Down

0 comments on commit b202e91

Please sign in to comment.