#[cfg(any(
feature = "http",
feature = "mcp",
feature = "cli-executor",
feature = "cli-listener",
feature = "lockfile",
feature = "subprocess-reaper"
))]
pub fn no_window(command: &mut tokio::process::Command) {
#[cfg(windows)]
{
use std::os::windows::process::CommandExt;
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
command.creation_flags(CREATE_NO_WINDOW);
}
#[cfg(not(windows))]
{
let _ = command;
}
}
#[cfg(all(unix, any(feature = "lockfile", feature = "subprocess-reaper")))]
pub fn kill_pid(pid: u32) -> usize {
let rc = unsafe { nix::libc::kill(pid as nix::libc::pid_t, nix::libc::SIGTERM) };
if rc == 0 { 1 } else { 0 }
}
#[cfg(all(windows, any(feature = "lockfile", feature = "subprocess-reaper")))]
pub fn kill_pid(pid: u32) -> usize {
use windows_sys::Win32::Foundation::CloseHandle;
use windows_sys::Win32::System::Threading::{
OpenProcess, PROCESS_TERMINATE, TerminateProcess,
};
unsafe {
let handle = OpenProcess(PROCESS_TERMINATE, 0, pid);
if handle.is_null() {
return 0;
}
let ok = TerminateProcess(handle, 1);
CloseHandle(handle);
if ok != 0 { 1 } else { 0 }
}
}