@@ -745,11 +745,13 @@ async fn send(args: SendArgs) -> anyhow::Result<()> {
745745 #[ cfg( feature = "clipboard" ) ]
746746 {
747747 use crossterm:: event:: { Event , EventStream , KeyCode , KeyEvent , KeyEventKind , KeyModifiers } ;
748+
749+ #[ cfg( any( unix, windows) ) ]
750+ use std:: io;
751+
748752 #[ cfg( unix) ]
749- use nix:: {
750- sys:: signal:: { kill, Signal } ,
751- unistd:: Pid ,
752- } ;
753+ use libc:: { raise, SIGINT } ;
754+
753755 #[ cfg( windows) ]
754756 use windows_sys:: Win32 :: System :: Console :: { GenerateConsoleCtrlEvent , CTRL_C_EVENT } ;
755757
@@ -786,13 +788,20 @@ async fn send(args: SendArgs) -> anyhow::Result<()> {
786788 . unwrap_or_else ( |e| eprintln ! ( "Failed to disable raw mode: {e}" ) ) ;
787789
788790 #[ cfg( unix) ]
789- kill ( Pid :: from_raw ( 0 ) , Some ( Signal :: SIGINT ) )
790- . unwrap_or_else ( |e| eprintln ! ( "Failed to end process: {e}" ) ) ;
791+ // Safety: Raw syscall to re-send the SIGINT signal to the console.
792+ // `raise` returns nonzero for failure.
793+ if unsafe { raise ( SIGINT ) } != 0 {
794+ eprintln ! ( "Failed to raise signal: {}" , io:: Error :: last_os_error( ) ) ;
795+ }
791796
792797 #[ cfg( windows) ]
793- // Safety: Raw syscall to re-send the Ctrl+C event to the console
798+ // Safety: Raw syscall to re-send the Ctrl+C event to the console.
799+ // `GenerateConsoleCtrlEvent` returns 0 for failure.
794800 if unsafe { GenerateConsoleCtrlEvent ( CTRL_C_EVENT , 0 ) } == 0 {
795- eprintln ! ( "Failed to end process: {}" , std:: io:: Error :: last_os_error( ) ) ;
801+ eprintln ! (
802+ "Failed to generate console event: {}" ,
803+ io:: Error :: last_os_error( )
804+ ) ;
796805 }
797806 }
798807 _ => { }
0 commit comments