From 94b90043f98499a1ed3594dd9ea42b2aef62b93a Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Wed, 6 May 2026 20:17:52 +0300 Subject: fix: clear native agent detection after shell returns fixes #66 --- src/platform/fallback.rs | 5 +++++ src/platform/linux.rs | 6 +++--- src/platform/macos.rs | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src/platform') 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 @@ -7,6 +7,11 @@ pub fn foreground_job(_child_pid: u32) -> Option { None } +/// Unsupported platform stub. +pub fn foreground_process_group_id(_child_pid: u32) -> Option { + None +} + /// Unsupported platform stub. pub fn process_cwd(_pid: u32) -> Option { 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 { - 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 { }) } -fn foreground_pgid(child_pid: u32) -> Option { +pub fn foreground_process_group_id(child_pid: u32) -> Option { // /proc//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 { 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 { 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 { /// Read `e_tpgid` (foreground process group of the controlling terminal) /// for the given PID. -fn foreground_pgid(pid: u32) -> Option { +pub fn foreground_process_group_id(pid: u32) -> Option { let mut info: libc::proc_bsdinfo = unsafe { std::mem::zeroed() }; let size = std::mem::size_of::() as libc::c_int; -- cgit v1.2.3