/* * This file is part of agent686 * Copyright (C) 2026 Salmonik * SPDX-License-Identifier: GPL-3.0-or-later * https://git.2137697.xyz/agent686 */ use std::sync::atomic::{AtomicBool, Ordering}; /// Set by the first Ctrl-C. Cleared between turns. pub static CANCEL: AtomicBool = AtomicBool::new(false); extern "C" fn handler(_: libc::c_int) { // First Ctrl-C aborts the turn. A second one is taken to mean "I really mean // it" and leaves immediately; `_exit` is async-signal-safe, `exit` is not. if CANCEL.swap(true, Ordering::SeqCst) { unsafe { libc::_exit(130) } } } pub fn install() { let handler: extern "C" fn(libc::c_int) = handler; unsafe { libc::signal(libc::SIGINT, handler as libc::sighandler_t); } }