Comments (2)
I found this comment:
Running our handler in its own thread is unfortunate, but we cannot safely allow arbitrary rust code to run in the os_handler() since most operations are not async signal safe.
What if ctrlc
exposed an unsafe API to register a user handler to be run directly in the os_handler()
?
from rust-ctrlc.
That comment is correct, most rust code would be unsafe when called from the OS signal handler on a POSIX system. Signal handlers are special, you can only use special async-signal safe functions, this means no memory allocation, no box or vecs, no panicing and more. Allowing registering of raw OS handlers wouldn’t be very useful, if you absolutely need to do this, you can do the libc call to setup the signal handler yourself. On windows, the OS spins up a new thread for the incoming signals, so here it would actually be safe call arbitrary rust code, but exposing this would not be cross platform.
The safe and cross platfrom solution is to provide an API with an custom safe abstraction over these atomic flag/counter type signal handlers, this can be implement without the extra thread, which means no race. Here is my suggestion #27 for adding this, but I have not had the time implement anything yet.
from rust-ctrlc.
Related Issues (20)
- MultipleHandler's using nohup to run binary HOT 8
- error[E0015]: calls in statics are limited HOT 1
- Add `revert_to_default()` or similar HOT 6
- Missing tag for 3.2.4 HOT 1
- Switch to rustix? HOT 1
- Problem in win11 with powershell 7.4.1 (fine in command prompt) HOT 1
- Closure type taken by `set_handler()` should be `FnMut` HOT 8
- Ctrl+C is awkward with Windows HOT 5
- ctrl-c not working when key remapped on linux HOT 2
- v3.1.5 ctrlc::set_handler() weird errors HOT 2
- Need to bump Nix to pick up fix for riscv64 HOT 1
- termination feature infects the entire workspace HOT 4
- Simpler example without busy loop but channels HOT 2
- Handling runs after the loop executes HOT 2
- update nix to 0.23 HOT 2
- Migrate to `windows`/`-sys` crate HOT 2
- Switch back stream to its initial flags ? HOT 2
- Handler code does not finish HOT 2
- Possible memory leak? HOT 1
- Use signal-hook-registry for listening to signals HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-ctrlc.