Best cross-platform signal handling?


#1

Hi all,

I’m looking to handle signals in my application (fac), to ensure things get cleaned up. Most important, of course, is ctrl-C handling (SIGINT on posix systems, weird on windows), which is very important to handle properly. Handling SIGTERM and others would also be nice, but is less crucial, because those signals are much less common than a user hitting ctrl-C on a long build.

The only crate I’ve encountered to do this in a cross-platform way is ctrlc, which looks reasonable for ctrl-C handling, and can even handle SIGTERM, but doesn’t seem to support separate handlers for SIGINT vs. SIGTERM, which seems a major drawback.

Are there any options that I’ve missed, or any suggestions for a good way to approach this task? Anything bug ctrl-C I could be happy handling in a way that unifies with something like atexit handling, i.e. a library for cleanup tasks, if such a thing exists.

David