#signal #unix #daemon

signal-hook

Unix signal handling

9 releases

0.1.8 Feb 25, 2019
0.1.7 Dec 26, 2018
0.1.6 Nov 11, 2018
0.1.5 Sep 20, 2018
0.1.0 Jun 22, 2018

#1 in Unix APIs

Download history 7357/week @ 2018-11-13 5636/week @ 2018-11-20 6604/week @ 2018-11-27 7153/week @ 2018-12-04 6972/week @ 2018-12-11 5908/week @ 2018-12-18 6513/week @ 2018-12-25 9101/week @ 2019-01-01 11410/week @ 2019-01-08 19350/week @ 2019-01-15 17959/week @ 2019-01-22 17770/week @ 2019-01-29 19782/week @ 2019-02-05 20104/week @ 2019-02-12 21296/week @ 2019-02-19

56,075 downloads per month
Used in 217 crates (19 directly)

Apache-2.0/MIT

59KB
551 lines

Signal-hook

Travis Build Status

Library for safe and correct Unix signal handling in Rust.

Unix signals are inherently hard to handle correctly, for several reasons:

  • They are a global resource. If a library wants to set its own signal handlers, it risks disturbing some other library. It is possible to chain the previous signal handler, but then it is impossible to remove the old signal handlers from the chains in any practical manner.
  • They can be called from whatever thread, requiring synchronization. Also, as they can interrupt a thread at any time, making most handling race-prone.
  • According to the POSIX standard, the set of functions one may call inside a signal handler is limited to very few of them. To highlight, mutexes (or other locking mechanisms) and memory allocation and deallocation are not allowed.

This library aims to solve some of the problems. It provides a global registry of actions performed on arrival of signals. It is possible to register multiple actions for the same signal and it is possible to remove the actions later on. If there was a previous signal handler when the first action for a signal is registered, it is chained (but the original one can't be removed).

Besides the basic registration of an arbitrary action, several helper actions are provided to cover the needs of the most common use cases.

For further details, see the documentation.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1.5MB
~18K SLoC