mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-20 06:56:17 -05:00
fix: improve error handling when spawning child processes
This commit is contained in:
4 files changed
+26
-30
No files matched your search
@@ -177,18 +177,16 @@ impl<'a> SamlAuthLauncher<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut non_root_cmd = auth_cmd.into_non_root()?;
|
let mut non_root_cmd = auth_cmd.into_non_root()?;
|
||||||
let child = non_root_cmd
|
let child = non_root_cmd.kill_on_drop(true).stdout(Stdio::piped()).spawn();
|
||||||
.kill_on_drop(true)
|
|
||||||
.stdout(Stdio::piped())
|
|
||||||
.spawn();
|
|
||||||
|
|
||||||
if child.is_err() {
|
let child = match child {
|
||||||
bail!("Failed to spawn {}: {}", program, child.unwrap_err())
|
Ok(child) => child,
|
||||||
}
|
Err(err) => {
|
||||||
|
bail!("Failed to spawn {}: {}", program, err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let output = child.unwrap()
|
let output = child.wait_with_output().await?;
|
||||||
.wait_with_output()
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let Ok(auth_result) = serde_json::from_slice::<SamlAuthResult>(&output.stdout) else {
|
let Ok(auth_result) = serde_json::from_slice::<SamlAuthResult>(&output.stdout) else {
|
||||||
bail!("Failed to parse auth data")
|
bail!("Failed to parse auth data")
|
||||||
|
|||||||
@@ -50,11 +50,12 @@ impl<'a> GuiHelperLauncher<'a> {
|
|||||||
|
|
||||||
info!("Launching gpgui-helper");
|
info!("Launching gpgui-helper");
|
||||||
let mut non_root_cmd = cmd.into_non_root()?;
|
let mut non_root_cmd = cmd.into_non_root()?;
|
||||||
let result = non_root_cmd.kill_on_drop(true).stdin(Stdio::piped()).spawn();
|
let child = non_root_cmd.kill_on_drop(true).stdin(Stdio::piped()).spawn();
|
||||||
if result.is_err() {
|
let mut child = match child {
|
||||||
bail!("Failed to spawn {}: {}", self.program.display(), result.unwrap_err())
|
Ok(child) => child,
|
||||||
}
|
Err(err) => bail!("Failed to spawn {}: {}", self.program.display(), err),
|
||||||
let mut child = result.unwrap();
|
};
|
||||||
|
|
||||||
let Some(mut stdin) = child.stdin.take() else {
|
let Some(mut stdin) = child.stdin.take() else {
|
||||||
bail!("Failed to open stdin");
|
bail!("Failed to open stdin");
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -69,11 +69,12 @@ impl<'a> GuiLauncher<'a> {
|
|||||||
|
|
||||||
info!("Launching gpgui");
|
info!("Launching gpgui");
|
||||||
let mut non_root_cmd = cmd.into_non_root()?;
|
let mut non_root_cmd = cmd.into_non_root()?;
|
||||||
let result = non_root_cmd.kill_on_drop(true).stdin(Stdio::piped()).spawn();
|
let child = non_root_cmd.kill_on_drop(true).stdin(Stdio::piped()).spawn();
|
||||||
if result.is_err() {
|
let mut child = match child {
|
||||||
bail!("Failed to spawn {}: {}", self.program.display(), result.unwrap_err())
|
Ok(child) => child,
|
||||||
}
|
Err(err) => bail!("Failed to spawn {}: {}", self.program.display(), err),
|
||||||
let mut child = result.unwrap();
|
};
|
||||||
|
|
||||||
let Some(mut stdin) = child.stdin.take() else {
|
let Some(mut stdin) = child.stdin.take() else {
|
||||||
bail!("Failed to open stdin");
|
bail!("Failed to open stdin");
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -72,18 +72,14 @@ impl<'a> HipLauncher<'a> {
|
|||||||
cmd.env("APP_VERSION", client_version);
|
cmd.env("APP_VERSION", client_version);
|
||||||
}
|
}
|
||||||
|
|
||||||
let child = cmd
|
let child = cmd.kill_on_drop(true).stdout(Stdio::piped()).spawn();
|
||||||
.kill_on_drop(true)
|
|
||||||
.stdout(Stdio::piped())
|
|
||||||
.spawn();
|
|
||||||
|
|
||||||
if child.is_err() {
|
let child = match child {
|
||||||
bail!("Failed to spawn {}: {}", self.program, child.unwrap_err())
|
Ok(child) => child,
|
||||||
}
|
Err(err) => bail!("Failed to spawn {}: {}", self.program, err),
|
||||||
|
};
|
||||||
|
|
||||||
let output = child.unwrap()
|
let output = child.wait_with_output().await?;
|
||||||
.wait_with_output()
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
if let Some(exit_status) = output.status.code() {
|
if let Some(exit_status) = output.status.code() {
|
||||||
if exit_status != 0 {
|
if exit_status != 0 {
|
||||||
|
|||||||
Reference in new issue
Block a user