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 exec() to delegate to the real cargo/rustc on Unix #31

Closed
alexcrichton opened this issue Oct 31, 2015 · 6 comments · Fixed by #1242
Closed

Use exec() to delegate to the real cargo/rustc on Unix #31

alexcrichton opened this issue Oct 31, 2015 · 6 comments · Fixed by #1242

Comments

@alexcrichton
Copy link
Member

Right now the Command API is presumably used which is cross platform (yay!) but doesn't provide the best experience on Unix. For example if I gdb cargo it doesn't actually gdb the Cargo executable itself but rather the shim. If, however, exec were used to spawn the new process then gdb I believe should naturally "just work".

Plus there's the added benefit of fewer processes sticking around!

@Diggsey
Copy link
Contributor

Diggsey commented Oct 31, 2015

Sounds reasonable. When I fix #30 you should be able to do multirust proxy gdb cargo too, and it will work regardless.

@nagisa
Copy link
Member

nagisa commented Nov 20, 2016

Needs more priority. People are getting bitten by this when trying to get backtraces for ICEs.

@Diggsey
Copy link
Contributor

Diggsey commented May 4, 2017

This may be problematic: #972 (comment)

@RalfJung
Copy link
Member

RalfJung commented Jul 12, 2017

@brson

This does solve the problem, but I want to solve these two issues a different way, and the main reason is that rustup wants to be able to perform work after the invoked subcommand is run (e.g. recording telemetry about the results). I am not prepared to give up that capability yet.

What kind of telemetry would that be? Is anything like that actually being done? It seems like currently, there are unsolved issues affecting users caused by using fork-exec, for the benefit of some potential future feature. Or have I entirely missed some rustup functionality? (Wouldn't be the first time.^^)

Maybe another option would be to spawn some "watcher" process, exec in the main process (so signals etc. work properly), and have the "watcher" perform whatever has to be done when the subprocess terminates? Not sure however if that would actually be simpler.

EDIT: I just saw rustup telemetry for the first time. oO Unfortunately, the help message gives 0 indication for what exactly is covered by "telemetry", but I must have entirely missed this.
Sorry.

@geofft
Copy link

geofft commented Jul 12, 2017

Maybe another option would be to spawn some "watcher" process, exec in the main process (so signals etc. work properly), and have the "watcher" perform whatever has to be done when the subprocess terminates? Not sure however if that would actually be simpler.

That seems like the right model, and as an example, strace -D does exactly this: "Run tracer process as a detached grandchild, not as parent of the tracee. This reduces the visible effect of strace by keeping the tracee a direct child of the calling process." Compare what happens if you send a Ctrl-C to, say, strace python vs. strace -D python.

We don't want to ptrace the child process (otherwise gdb cargo wouldn't work), so there's not a great cross-platform way to be notified when it exits. But I'm guessing the motivation for telemetry is to track commands known to rustup (rustc and cargo, in particular), and not arbitrary processes run by either rustc run or cargo run.

So that suggests a reasonably straightforward strategy: if rustup is running rustc or cargo, open a libc::pipe(), pass the reader end to the watcher process, and add a --rustup-fd option to rustc and cargo and let the writer end be inherited when you exec those commands. They should learn to close this fd when they exit, or in the case of cargo run, just before they exec the target command. (In the future you could pass info over this fd.) Then the watcher process can just block on reading the pipe. Don't bother setting up a watcher or a pipe for rustup run commands other than rustc or cargo, just exec the command like normal.

Is it reasonable to add this form of rustup awareness to rustc and cargo?

You could also just pass the fd and not tell the child process about it, but leaking file descriptors is vaguely poor form, and if you're using rustup run or cargo run to launch a long-running process, it's nice not to leave the watcher process around.

Also, exempting cargo run from telemetry might be simpler and worth doing as a stopgap - #806 and #845 (marked as dupes of this issue) are specifically about cargo run, and it's unfortunate that cargo itself execs (rust-lang/cargo#2343) but rustup prevents this from doing what you want.

@nagisa
Copy link
Member

nagisa commented Jul 13, 2017 via email

alexcrichton added a commit to alexcrichton/rustup.rs that referenced this issue Aug 22, 2017
This is only possible when telemetry is disabled, but almost all of the time it
is! This should help fix lots of common rustup-related issues related to signals
and such.

Closes rust-lang#31
Closes rust-lang#806
bors added a commit that referenced this issue Aug 22, 2017
Use `exec` on Unix to propagate signals

This is only possible when telemetry is disabled, but almost all of the time it
is! This should help fix lots of common rustup-related issues related to signals
and such.

Closes #31
Closes #806
alexcrichton added a commit to alexcrichton/rustup.rs that referenced this issue Aug 22, 2017
This is only possible when telemetry is disabled, but almost all of the time it
is! This should help fix lots of common rustup-related issues related to signals
and such.

Closes rust-lang#31
Closes rust-lang#806
bors added a commit that referenced this issue Aug 22, 2017
Use `exec` on Unix to propagate signals

This is only possible when telemetry is disabled, but almost all of the time it
is! This should help fix lots of common rustup-related issues related to signals
and such.

Closes #31
Closes #806
mattico pushed a commit to mattico/rustup.rs that referenced this issue Apr 5, 2018
This is only possible when telemetry is disabled, but almost all of the time it
is! This should help fix lots of common rustup-related issues related to signals
and such.

Closes rust-lang#31
Closes rust-lang#806
djc added a commit that referenced this issue Jun 18, 2024
# This is the 1st commit message:

Port cli_inst_interactive to CliTestContext

# The commit message #2 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #3 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #4 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #5 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #6 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #7 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #8 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #9 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #10 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #11 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #12 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #13 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #14 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #15 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #16 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #17 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #18 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #19 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #20 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #21 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #22 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #23 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #24 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #25 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #26 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #27 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #28 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #29 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #30 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #31 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #32 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #33 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #34 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #35 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #36 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #37 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #38 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #39 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext

# The commit message #40 will be skipped:

# fixup! Port cli_inst_interactive to CliTestContext
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.

5 participants