Release 3.0.2

This commit is contained in:
Kevin Yue committed 2026-10-12 00:26:32 +08:00
1 parent 580b81e7bb
commit 888f288c0d
54 files changed
+4007 -374

No files matched your search

+108 -21
View File
@@ -1,9 +1,9 @@
use std::{collections::HashMap, path::PathBuf, process::Stdio};
use std::{collections::HashMap, path::PathBuf};
use anyhow::bail;
use common::binary_paths;
use log::info;
use tokio::{io::AsyncWriteExt, process::Command};
use tokio::process::Command;
use tokio_util::sync::CancellationToken;
use crate::service::transport::SessionCredential;
@@ -34,7 +34,7 @@ impl<'a> GuiHelperLauncher<'a> {
self
}
pub async fn launch(&self) -> anyhow::Result<()> {
pub async fn launch(&self, cancellation: &CancellationToken) -> anyhow::Result<()> {
let mut cmd = Command::new(&self.program);
if let Some(envs) = self.envs {
@@ -53,23 +53,110 @@ impl<'a> GuiHelperLauncher<'a> {
uzers::get_effective_uid() != 0,
"The desktop GUI must not be launched by root"
);
let child = cmd.kill_on_drop(true).stdin(Stdio::piped()).spawn();
let mut child = match child {
Ok(child) => child,
Err(err) => bail!("Failed to spawn {}: {}", self.program.display(), err),
};
let Some(mut stdin) = child.stdin.take() else {
bail!("Failed to open stdin");
};
let frame = self.credential.encode_frame()?;
stdin.write_all(&frame).await?;
let exit_status = child.wait().await?;
drop(stdin);
info!("gpgui-helper exited with: {}", exit_status);
super::desktop_child::launch_desktop_child(
"gpgui-helper",
cmd.into_std(),
self.envs,
self.credential,
cancellation,
)
.await?;
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::process::rendering_recovery::RenderingCrash;
use std::{fs, os::unix::fs::PermissionsExt};
fn fixture(dir: &tempfile::TempDir, credential: &SessionCredential, body: &str) -> PathBuf {
let path = dir.path().join("helper");
let length = credential.encode_frame().unwrap().len();
fs::write(
&path,
format!("#!/bin/sh\ndd bs=1 count={length} of=/dev/null 2>/dev/null || exit 1\n{body}\n"),
)
.unwrap();
fs::set_permissions(&path, fs::Permissions::from_mode(0o755)).unwrap();
path
}
#[tokio::test]
async fn propagates_helper_failure_and_preserves_stderr_in_desktop_log() {
let dir = tempfile::TempDir::new().unwrap();
let credential = SessionCredential::generate(uuid::Uuid::new_v4(), "test").unwrap();
let path = fixture(&dir, &credential, "printf 'download failed\\n' >&2; exit 23");
let log = dir.path().join("desktop.log");
fs::write(&log, "").unwrap();
let envs = HashMap::from([("GP_LOG_FILE".into(), log.to_str().unwrap().into())]);
let launcher = GuiHelperLauncher {
program: path,
envs: Some(&envs),
credential: &credential,
gui_version: None,
};
let error = launcher.launch(&CancellationToken::new()).await.unwrap_err();
assert!(error.to_string().contains("gpgui-helper exited with"), "{error:#}");
assert!(error.to_string().contains("23"));
assert_eq!(fs::read_to_string(log).unwrap(), "download failed\n");
}
#[tokio::test]
async fn recognizes_helper_rendering_crash_and_respects_explicit_override() {
let dir = tempfile::TempDir::new().unwrap();
let credential = SessionCredential::generate(uuid::Uuid::new_v4(), "test").unwrap();
let path = fixture(
&dir,
&credential,
"printf '(gpgui-helper:42): Gdk-Message: 12:00:00: Error 71 (Protocol error) dispatching to Wayland display\\n' >&2; exit 71",
);
let mut envs = HashMap::from([("WAYLAND_DISPLAY".into(), "wayland-0".into())]);
for override_value in [None, Some(""), Some("0"), Some("1")] {
if let Some(value) = override_value {
envs.insert("WEBKIT_DISABLE_DMABUF_RENDERER".into(), value.into());
}
let launcher = GuiHelperLauncher {
program: path.clone(),
envs: Some(&envs),
credential: &credential,
gui_version: None,
};
let error = launcher.launch(&CancellationToken::new()).await.unwrap_err();
let eligible =
cfg!(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd")) && override_value.is_none();
assert_eq!(error.downcast_ref::<RenderingCrash>().is_some(), eligible, "{error:#}");
}
}
#[tokio::test]
async fn cancellation_joins_helper_before_returning() {
let dir = tempfile::TempDir::new().unwrap();
let credential = SessionCredential::generate(uuid::Uuid::new_v4(), "test").unwrap();
let pid_file = dir.path().join("pid");
let body = format!("echo $$ > '{}'; exec sleep 30", pid_file.display());
let path = fixture(&dir, &credential, &body);
let envs = HashMap::new();
let launcher = GuiHelperLauncher {
program: path,
envs: Some(&envs),
credential: &credential,
gui_version: None,
};
let cancellation = CancellationToken::new();
let attempt = launcher.launch(&cancellation);
tokio::pin!(attempt);
tokio::select! {
result = &mut attempt => panic!("helper exited early: {result:?}"),
_ = async { while !pid_file.exists() { tokio::time::sleep(std::time::Duration::from_millis(10)).await; } } => {}
}
cancellation.cancel();
assert!(attempt.await.is_err());
let pid: i32 = fs::read_to_string(pid_file).unwrap().trim().parse().unwrap();
assert_eq!(
nix::sys::signal::kill(nix::unistd::Pid::from_raw(pid), None),
Err(nix::errno::Errno::ESRCH)
);
}
}