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

Properly implement scarb::process::exec_replace #125

Closed
mkaput opened this issue Mar 1, 2023 · 0 comments · Fixed by #658
Closed

Properly implement scarb::process::exec_replace #125

mkaput opened this issue Mar 1, 2023 · 0 comments · Fixed by #658
Assignees

Comments

@mkaput
Copy link
Member

mkaput commented Mar 1, 2023

Fix the TODO comment left there. Doc comment should fully describe what should happen internally.

// TODO(mkaput): Do what is documented here, take a look at what cargo-util does.
/// Replaces the current process with the target process.
///
/// On Unix, this executes the process using the Unix syscall `execvp`, which will block this
/// process, and will only return if there is an error.
///
/// On Windows this isn't technically possible. Instead we emulate it to the best of our ability.
/// One aspect we fix here is that we specify a handler for the Ctrl-C handler.
/// In doing so (and by effectively ignoring it) we should emulate proxying Ctrl-C handling to
/// the application at hand, which will either terminate or handle it itself.
/// According to Microsoft's documentation at
/// <https://docs.microsoft.com/en-us/windows/console/ctrl-c-and-ctrl-break-signals>.
/// the Ctrl-C signal is sent to all processes attached to a terminal, which should include our
/// child process. If the child terminates then we'll reap them in Cargo pretty quickly, and if
/// the child handles the signal then we won't terminate (and we shouldn't!) until the process
/// itself later exits.
#[tracing::instrument(level = "debug")]
pub fn exec_replace(cmd: &mut Command) -> Result<()> {
let exit_status = cmd
.spawn()
.with_context(|| format!("failed to spawn: {}", cmd.get_program().to_string_lossy()))?
.wait()
.with_context(|| {
format!(
"failed to wait for process to finish: {}",
cmd.get_program().to_string_lossy()
)
})?;
if exit_status.success() {
Ok(())
} else {
bail!("process did not exit successfully: {exit_status}");
}
}

@mkaput mkaput added this to the 0.2.0 milestone Mar 30, 2023
@mkaput mkaput modified the milestones: 0.2.0, 0.3.0 Apr 11, 2023
@mkaput mkaput removed this from the 0.3.0 milestone Apr 18, 2023
@mkaput mkaput assigned szymmis and unassigned 4rgorok Jul 10, 2023
@mkaput mkaput added the good first issue Good for newcomers label Aug 11, 2023
@mkaput mkaput removed the good first issue Good for newcomers label Sep 18, 2023
github-merge-queue bot pushed a commit that referenced this issue Sep 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants