ok/jj
1
0
Fork 0
forked from mirrors/jj

signing: ensure child processes are wait()ed on I/O error

This will also provide a better error indication. If write() failed, the child
process would presumably have exited with non-zero status and error message to
stderr.
This commit is contained in:
Yuya Nishihara 2024-03-02 20:26:06 +09:00
parent a09ee4b9a3
commit fa7864edeb
2 changed files with 9 additions and 9 deletions

View file

@ -68,9 +68,10 @@ fn parse_gpg_verify_output(
fn run_sign_command(command: &mut Command, input: &[u8]) -> Result<Vec<u8>, GpgError> { fn run_sign_command(command: &mut Command, input: &[u8]) -> Result<Vec<u8>, GpgError> {
let process = command.stderr(Stdio::piped()).spawn()?; let process = command.stderr(Stdio::piped()).spawn()?;
process.stdin.as_ref().unwrap().write_all(input)?; let write_result = process.stdin.as_ref().unwrap().write_all(input);
let output = process.wait_with_output()?; let output = process.wait_with_output()?;
if output.status.success() { if output.status.success() {
write_result?;
Ok(output.stdout) Ok(output.stdout)
} else { } else {
Err(GpgError::Command { Err(GpgError::Command {

View file

@ -60,18 +60,17 @@ fn parse_utf8_string(data: Vec<u8>) -> SshResult<String> {
fn run_command(command: &mut Command, stdin: &[u8]) -> SshResult<Vec<u8>> { fn run_command(command: &mut Command, stdin: &[u8]) -> SshResult<Vec<u8>> {
let process = command.spawn()?; let process = command.spawn()?;
process.stdin.as_ref().unwrap().write_all(stdin)?; let write_result = process.stdin.as_ref().unwrap().write_all(stdin);
let output = process.wait_with_output()?; let output = process.wait_with_output()?;
if output.status.success() {
if !output.status.success() { write_result?;
return Err(SshError::Command { Ok(output.stdout)
} else {
Err(SshError::Command {
exit_status: output.status, exit_status: output.status,
stderr: String::from_utf8_lossy(&output.stderr).trim_end().into(), stderr: String::from_utf8_lossy(&output.stderr).trim_end().into(),
}); })
} }
Ok(output.stdout)
} }
// This attempts to convert given key data into a file and return the filepath. // This attempts to convert given key data into a file and return the filepath.