-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Distinguish between different signals #26
Comments
I think this is a time for a serious decision making about whether we want CtrlC to be:
or
Originally I had planned the former, and rejected some improvement suggestions because of the simplicity vision. However, due to your massive contributions to the project (thanks a lot, by the way) I think no reason why wouldn't CtrlC do more than just handle I think mapping the signals together would be a better option; I would like to handle CtrlC and termination without knowing the details of either platform. I was even thinking of a more high level abstraction of the basics (ctrlc+termination) while allowing lower level access to signals if the user wants to go to the details. Something like: enum Signal {
Ctrlc(PlatformSignal),
Termination(PlatformSignal),
Other(PlatformSignal),
} where |
I'm in favor of having a moderately complex crate. I believe once you start trapping signals you'll want to trap more. Currently I'm looking at adding HUP/reload config support to Feather(a minecraft server) and it uses this crate. |
There are better signal handler libraries in the Rust ecosystem nowadays. I'm keeping |
This is in response to concerns raised by #21.
Currently we only allow the user to register a single handler that gets called for both
SIGINT
andSIGTERM
. There is similar situation on Windows, Windows actually distinguishes between aCTRL-C
event andCTRL-BREAK
event, but we call the same handler for both. Our API should allow the user distinguish between the different signals and allow them to take different actions on different signals.There are two different approaches we could take when implementing this, we can allow users to register different handlers per signal or we can pass the signal type as parameter to the handler. I am in favour of last option. Regardless of what option we choose, we need to come with a cross platform Signal Enum. Should we just throw Windows signal types and Unix signal types together in one Enum or should we try to map signal types from one platform to types on the other platform?
Another thing we should consider is that Windows supports events/signals similar to
SIGTERM
. A handler registered bySetConsoleCtrlHandler()
, in addition to being called onCTRL+C
andCTRL+BREAK
, will also be called for the following eventsCTRL_CLOSE_EVENT
,CTRL_LOGOFF_EVENT
andCTRL_SHUTDOWN_EVENT
. These events allow the user to preform clean up before termination, but unlike forCTRL-C
events, the process will terminate when the handler routine is done executing regardless of what the return value of handler routine was. If we wanted to, we could try to use this to implement cross platformSIGTERM
support, but we would have to work around the termination issue in some way. Edit: These events are probably closer in semantics toSIGHUP
thenSIGTERM
.There are also other Unix signals which might be worth exposing, like
SIGCHLD
,SIGCONT
,SIGHUP
,SIGTSTP
,SIGUSR1
andSIGUSR2
.The text was updated successfully, but these errors were encountered: