3

I'm writing a small shell for Windows in Rust, and want to kill the Command I spawned and prevent my shell from quitting.

Is there a way of capturing the Windows SIGINT equivalent in Rust?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
lines
  • 141
  • 5
  • The Windows console (conhost.exe) generates events in attached processes, such as `CTRL_C_EVENT`. Console processes can set handlers for these events. If the process is using Microsoft's C runtime, it installs a handler that calls its registered handler for the standard C `SIGINT` signal. If rust uses a CRT, it may provide a mechanism to ignore `SIGINT`, or at least some interface that lets you call C `signal(SIGINT, SIG_IGN)` or Win32 `SetConsoleCtrlHandler(NULL, TRUE)`. – Eryk Sun Jun 20 '15 at 18:02
  • I know that I could use FFI, however I would _like_ (not need) a somewhat native way to do this. (If someone tells me I need to use FFI, I will accept an Answer in that vein) – lines Jun 20 '15 at 18:14
  • Yeah, I said 'SIGINT equivalent' for a reason. – lines Jun 20 '15 at 18:36

1 Answers1

0

There is a crate, chan-signal, that aims to help in handling this, by spawning a thread and having it wait for signals.

EDIT: It doesn't currently support windows.

There is an RFC asking for this functionality to be integrated into the language's standard library, but it is very young.

It seems your option is to go with FFI.

iajrz
  • 749
  • 7
  • 16
  • If you do go the FFI way, please consider contributing to chan-signal, the author is [looking for support](http://burntsushi.net/rustdoc/chan_signal/#platform-support-no-windows-support) in that front. – iajrz Nov 25 '15 at 00:26