Skip to content
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

Use signal-hook-registry for listening to signals #97

Closed
notgull opened this issue Feb 6, 2023 · 5 comments
Closed

Use signal-hook-registry for listening to signals #97

notgull opened this issue Feb 6, 2023 · 5 comments

Comments

@notgull
Copy link

notgull commented Feb 6, 2023

It is unsound to use this crate and signal-hook in the same dependency graph, since they will both try to acquire the signal handler and one will overwrite the other. This issue can be fixed by changing the signal handling backend to rely on the signal-hook-registry crate.

@Detegr
Copy link
Owner

Detegr commented Feb 9, 2023

Hi, thank you for your contribution.

What is the use case where there would be multiple crates handing signals? This crate and signal-hook are more or less doing the same thing internally, so it makes sense that they conflict.

Trying to be compatible with other crates doing signal handling feels a bit dangerous and error prone to me. I would rather "fix" this by implementing this TODO so that registering signals would fail if there's already a handler in place.

@notgull
Copy link
Author

notgull commented Feb 9, 2023

What is the use case where there would be multiple crates handing signals?

There could be multiple crates in the dependency graph where one could use signal-hook and another could use ctrlc.

Trying to be compatible with other crates doing signal handling feels a bit dangerous and error prone to me.

On the contrary, it's actually less error prone to just use one universal crate for signal handling.

I would rather "fix" this by implementing this TODO so that registering signals would fail if there's already a handler in place

This would be an acceptable solution, since signal-hook-registry handles the case where there is already a solution. However, I think it would be better to just be signal-hook-registry compatible.

@Detegr
Copy link
Owner

Detegr commented May 20, 2023

Fixed with release 3.3.0.

@Detegr Detegr closed this as completed May 20, 2023
@jdx
Copy link

jdx commented May 22, 2023

this change makes my CLI break when I do the following in a bash script:

trap -- '' SIGINT;
mycli

The error:

The application panicked (crashed).
Message:  Error setting Ctrl-C handler: MultipleHandlers
Location: src/main.rs:93

is this intended? or was this change only suppose to impact when a signal was caught within the same process? I suppose I can simply ignore the error but wanted to make sure this is working as expected.

@Detegr
Copy link
Owner

Detegr commented May 22, 2023

I think in that case the mycli program inherits the signal handlers from the parent, so it is working as expected in that regard. The previous implementation would've just overwritten the handler. mycli could set the handler manually to SIG_DFL beforehand if the application wanted to have its own signal handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants