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

Subcommands that take their time with exit cleanup make the shell prompt weird #3959

Closed
golddranks opened this issue Apr 27, 2017 · 4 comments · Fixed by #3970
Closed

Subcommands that take their time with exit cleanup make the shell prompt weird #3959

golddranks opened this issue Apr 27, 2017 · 4 comments · Fixed by #3970

Comments

@golddranks
Copy link
Contributor

golddranks commented Apr 27, 2017

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?

@alexcrichton
Copy link
Member

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 exec_replace when executing subcommands, whereas today we probably don't use exec

@golddranks
Copy link
Contributor Author

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 exec shouldn't break anything?

@alexcrichton
Copy link
Member

Yeah should be reasonable to implement, would you be interested in sending a PR for this?

@golddranks
Copy link
Contributor Author

Sent a PR!

bors added a commit that referenced this issue Apr 28, 2017
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`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants