diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-05-06 20:17:52 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-05-06 20:17:52 +0300 |
| commit | 94b90043f98499a1ed3594dd9ea42b2aef62b93a (patch) | |
| tree | 2f19157650b5010d91d815ee4afd4d54d2519fe2 /src/platform | |
| parent | f7b0ee2f758440db3a3ff4cc727f879b420255d7 (diff) | |
fix: clear native agent detection after shell returns
fixes #66
Diffstat (limited to 'src/platform')
| -rw-r--r-- | src/platform/fallback.rs | 5 | ||||
| -rw-r--r-- | src/platform/linux.rs | 6 | ||||
| -rw-r--r-- | src/platform/macos.rs | 4 |
3 files changed, 10 insertions, 5 deletions
diff --git a/src/platform/fallback.rs b/src/platform/fallback.rs index e90cdaf0..7addbc5d 100644 --- a/src/platform/fallback.rs +++ b/src/platform/fallback.rs @@ -8,6 +8,11 @@ pub fn foreground_job(_child_pid: u32) -> Option<ForegroundJob> { } /// Unsupported platform stub. +pub fn foreground_process_group_id(_child_pid: u32) -> Option<u32> { + None +} + +/// Unsupported platform stub. pub fn process_cwd(_pid: u32) -> Option<PathBuf> { None } diff --git a/src/platform/linux.rs b/src/platform/linux.rs index dc944cd9..13aa6ec8 100644 --- a/src/platform/linux.rs +++ b/src/platform/linux.rs @@ -8,7 +8,7 @@ use super::{ClipboardCommand, ForegroundJob, ForegroundProcess, Signal}; /// Collect the foreground terminal job for a given child PID. pub fn foreground_job(child_pid: u32) -> Option<ForegroundJob> { - let tpgid = foreground_pgid(child_pid)? as u32; + let tpgid = foreground_process_group_id(child_pid)?; let mut processes = Vec::new(); for entry in std::fs::read_dir("/proc").ok()? { @@ -49,7 +49,7 @@ pub fn foreground_job(child_pid: u32) -> Option<ForegroundJob> { }) } -fn foreground_pgid(child_pid: u32) -> Option<i32> { +pub fn foreground_process_group_id(child_pid: u32) -> Option<u32> { // /proc/<pid>/stat format: "pid (comm) state ppid pgrp session tty_nr tpgid ..." // The (comm) field can contain spaces and parens, so we find the last ')' first. let stat = std::fs::read_to_string(format!("/proc/{child_pid}/stat")).ok()?; @@ -57,7 +57,7 @@ fn foreground_pgid(child_pid: u32) -> Option<i32> { let fields: Vec<&str> = rest.split_whitespace().collect(); // After (comm): state(0) ppid(1) pgrp(2) session(3) tty_nr(4) tpgid(5) let tpgid: i32 = fields.get(5)?.parse().ok()?; - (tpgid > 0).then_some(tpgid) + (tpgid > 0).then_some(tpgid as u32) } fn process_pgrp_and_comm(pid: u32) -> Option<(i32, String)> { diff --git a/src/platform/macos.rs b/src/platform/macos.rs index f5de67ce..43c24386 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -12,7 +12,7 @@ pub fn foreground_job(child_pid: u32) -> Option<ForegroundJob> { return None; } - let fg_pgid = foreground_pgid(child_pid)?; + let fg_pgid = foreground_process_group_id(child_pid)?; let mut pids = vec![0i32; 4096]; let bytes = unsafe { libc::proc_listallpids( @@ -62,7 +62,7 @@ pub fn foreground_job(child_pid: u32) -> Option<ForegroundJob> { /// Read `e_tpgid` (foreground process group of the controlling terminal) /// for the given PID. -fn foreground_pgid(pid: u32) -> Option<u32> { +pub fn foreground_process_group_id(pid: u32) -> Option<u32> { let mut info: libc::proc_bsdinfo = unsafe { std::mem::zeroed() }; let size = std::mem::size_of::<libc::proc_bsdinfo>() as libc::c_int; |
