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

exit(130) is not the same as raise(SIGINT) #854

Closed
tavianator opened this issue Sep 17, 2021 · 3 comments
Closed

exit(130) is not the same as raise(SIGINT) #854

tavianator opened this issue Sep 17, 2021 · 3 comments
Assignees
Labels
Milestone

Comments

@tavianator
Copy link
Collaborator

fd handles ^C by propagating ExitCode::KilledBySigint up to main() which does process::exit(exit_code.into()). But exit code 130 is a lie told by bash (this comment has a good explanation: rust-lang/rust#62569 (comment)).

This is observable from programs that check WIFEXITED()/WIFSIGNALED(). Here's a crude example:

$ bfs -D exec /dev/null -exec fd . / \; >/dev/null & sleep 1; pkill -INT fd; wait %1
bfs: -D exec: -exec: Executing 'fd' ... [2 arguments]
bfs: warning: Command 'fd' terminated by signal 2 (Interrupt)
$ bfs -D exec /dev/null -exec fd --color=always . / \; >/dev/null & sleep 1; pkill -INT fd; wait %1
bfs: -D exec: -exec: Executing 'fd' ... [3 arguments]
bfs: -D exec: -exec: Command 'fd' failed with status 130

The right way to pretend to die by SIGINT is something like signal(SIGINT, SIG_DFL); raise(SIGINT);.

@tavianator tavianator added the bug label Sep 17, 2021
@tavianator tavianator self-assigned this Sep 17, 2021
@sharkdp
Copy link
Owner

sharkdp commented Nov 14, 2021

Thank you for reporting this. I guess this should be easy to fix using sth. like nix::sys::signal::raise?

Or maybe we avoid that dependency and add some unsafe code using libc::raise directly? nix is in the dependency tree via ctrlc anyway.

@tavianator
Copy link
Collaborator Author

Yeah that's what I was thinking. Didn't get around to it yet because I'm not sure what the right behavior is on Windows. But I could at least fix it on *nix first

tavianator added a commit to tavianator/fd that referenced this issue Nov 14, 2021
tavianator added a commit to tavianator/fd that referenced this issue Nov 14, 2021
tavianator added a commit to tavianator/fd that referenced this issue Nov 14, 2021
tavianator added a commit to tavianator/fd that referenced this issue Nov 14, 2021
@tmccombs
Copy link
Collaborator

using raise is the right way to do it on *nix. I have no idea about windows though. Windows doesn't even use signals as I understand it.

@sharkdp sharkdp added this to the fd 8.3 milestone Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants