{"id":13595182,"url":"https://github.com/vorner/signal-hook","last_synced_at":"2025-05-13T16:12:08.686Z","repository":{"id":37492913,"uuid":"137260008","full_name":"vorner/signal-hook","owner":"vorner","description":"Rust library allowing to register multiple handlers for the same signal","archived":false,"fork":false,"pushed_at":"2025-04-21T06:47:49.000Z","size":697,"stargazers_count":769,"open_issues_count":19,"forks_count":78,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-23T22:58:43.462Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vorner.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-06-13T19:14:25.000Z","updated_at":"2025-04-23T17:36:35.000Z","dependencies_parsed_at":"2024-06-07T09:54:48.537Z","dependency_job_id":"9b3006b1-95f9-44b0-a130-af58a0133639","html_url":"https://github.com/vorner/signal-hook","commit_stats":{"total_commits":231,"total_committers":27,"mean_commits":8.555555555555555,"dds":"0.21645021645021645","last_synced_commit":"61e2cf6db7511459b9683e3f1d74402c6c1a01d2"},"previous_names":[],"tags_count":61,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vorner%2Fsignal-hook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vorner%2Fsignal-hook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vorner%2Fsignal-hook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vorner%2Fsignal-hook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vorner","download_url":"https://codeload.github.com/vorner/signal-hook/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250528726,"owners_count":21445514,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T16:01:45.436Z","updated_at":"2025-04-23T22:58:50.902Z","avatar_url":"https://github.com/vorner.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# Signal-hook\n\n[![Actions Status](https://github.com/vorner/signal-hook/workflows/test/badge.svg)](https://github.com/vorner/signal-hook/actions)\n[![codecov](https://codecov.io/gh/vorner/signal-hook/branch/master/graph/badge.svg?token=3KA3R2D9fV)](https://codecov.io/gh/vorner/signal-hook)\n[![docs](https://docs.rs/signal-hook/badge.svg)](https://docs.rs/signal-hook)\n\nLibrary for safe and correct Unix signal handling in Rust.\n\nUnix signals are inherently hard to handle correctly, for several reasons:\n\n* They are a global resource. If a library wants to set its own signal handlers,\n  it risks disturbing some other library. It is possible to chain the previous\n  signal handler, but then it is impossible to remove the old signal handlers\n  from the chains in any practical manner.\n* They can be called from whatever thread, requiring synchronization. Also, as\n  they can interrupt a thread at any time, making most handling race-prone.\n* According to the POSIX standard, the set of functions one may call inside a\n  signal handler is limited to very few of them. To highlight, mutexes (or other\n  locking mechanisms) and memory allocation and deallocation are *not* allowed.\n\nThis library aims to solve some of the problems. It provides a global registry\nof actions performed on arrival of signals. It is possible to register multiple\nactions for the same signal and it is possible to remove the actions later on.\nIf there was a previous signal handler when the first action for a signal is\nregistered, it is chained (but the original one can't be removed).\n\nBesides the basic registration of an arbitrary action, several helper actions\nare provided to cover the needs of the most common use cases, available from\nsafe Rust.\n\nFor further details, see the [documentation](https://docs.rs/signal-hook).\n\n## Example\n\n(This likely does a lot more than you need in each individual application, it's\nmore of a show-case of what everything is possible, not of what you need to do\neach time).\n\n```rust\nuse std::io::Error;\nuse std::sync::Arc;\nuse std::sync::atomic::{AtomicBool, Ordering};\n\nfn main() -\u003e Result\u003c(), Error\u003e {\n    let term = Arc::new(AtomicBool::new(false));\n    signal_hook::flag::register(signal_hook::consts::SIGTERM, Arc::clone(\u0026term))?;\n    while !term.load(Ordering::Relaxed) {\n        // Do some time-limited stuff here\n        // (if this could block forever, then there's no guarantee the signal will have any\n        // effect).\n    }\n    Ok(())\n}\n```\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally\nsubmitted for inclusion in the work by you, as defined in the Apache-2.0\nlicense, shall be dual licensed as above, without any additional terms\nor conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvorner%2Fsignal-hook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvorner%2Fsignal-hook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvorner%2Fsignal-hook/lists"}