-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Subcommands that take their time with exit cleanup make the shell prompt weird #3959
Comments
Cargo doesn't currently handle signals, which means that if you ctrl-c Cargo you're sending a ctrl-c to the entire process group, killing Cargo and all child processes by default. As Cargo is typically the "controlling" process then the stdout/stderr pipes are torn down once Cargo itself dies and the host shell starts cleaning up. The "fix" here would probably be to use |
I was thinking the same. Is there anything that would prevent doing this? The way I understand it, Cargo just calls the subcommand and hands over (it doesn't do any substantial "cleanup" after the subcommand finishes), so using |
Yeah should be reasonable to implement, would you be interested in sending a PR for this? |
Sent a PR! |
exec (replace the current process) external subcommands instead of running them as child processes. This fixes #3959 (tested to be working with my yet-to-be-published subcommand, and tested not to break things with `cargo tree` and `cargo outdated`).
When cargo runs a(n external) subcommand, that subcommand can set signal handlers to respond to events like the user pressing Ctrl-C (I think this is the most common case). I noticed that if the process takes some time when exiting, the shell prompt appears too early, when the subcommand hasn't exited yet. If the subcommand prints something out on exit, this makes the shell prompt act weird.
When the subcommand binary is run as standalone, this doesn't happen. I think the problem is that because according to POSIX, all the processes in the process group receive the signal, both cargo and the subcommand receive it, but cargo returns immediately whereas the subcommand takes its time. Because cargo returns, the shell prints already its prompt, but this is garbled by the subcommand that prints exit messages.
Maybe cargo could wait for the subcommand to finish before exiting?
The text was updated successfully, but these errors were encountered: