diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 863c635..c9ed488 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -37,6 +37,7 @@ body: ```sh { + echo "== doctor (v0.2.17+)"; uuremote-server doctor echo "== 系统"; grep PRETTY_NAME /etc/os-release; uname -rm echo "== 桌面"; echo "session=$XDG_SESSION_TYPE desktop=$XDG_CURRENT_DESKTOP" echo "== 显示器"; xrandr --listmonitors 2>/dev/null diff --git a/AGENTS.md b/AGENTS.md index b62bb99..aef58b1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -152,7 +152,8 @@ every 60 s. | `src/viewer_main.rs`, `src/viewer/` | experimental viewer (`--features native-viewer,viewer-sdl`): cloud join, WebRTC offer side, SDL desktop window (ffmpeg CLI decode), files/terminal/portmap/power/assist tools, device removal (`POST /api/v1/device/{id}/unbind`, verified live; shared devices use `/api/v1/device/share/{id}/unbind`, strings only), GTK launcher | | `c_engine/viewer_window.c`, `c_engine/viewer_tools.c` | viewer GTK launcher and tool windows (files, port mapping, terminal list) | -Diagnostic subcommands: `login [--no-gui]`, `unlock-check` (password on stdin, prints only accepted/rejected), +Diagnostic subcommands: `doctor` (paste-safe report: session, selected backend, engine plugins, uinput, encoders, +default codec, sign-in/service state; booleans and names only), `login [--no-gui]`, `unlock-check` (password on stdin, prints only accepted/rejected), `desktop-probe [new.png]`, `desktop-video-probe` (`UU_PROBE_FPS`, `UU_PROBE_FRAMES`, `UU_PROBE_QUALITY` 1-5 = viewer bitrate preset, 5 auto; `UU_PROBE_INPUT` fixed video/image sequence, `UU_PROBE_LOOP=1` repeats), `wayland-input-probe`, `clipboard-acceptance`, `portal-acceptance`, `help`. Unknown arguments exit with code 2. Builds up to v0.1.0 did **not** reject them and started a second full host server instead, so check that a subcommand exists in the binary you run. diff --git a/README.en.md b/README.en.md index eeeb56a..16a7106 100644 --- a/README.en.md +++ b/README.en.md @@ -77,7 +77,8 @@ authorized session. Independent file/terminal tool peers do not reset input. | GNOME / KDE Plasma | Wayland (xdg-desktop-portal) | 🧪 Experimental; validation scope and limits below | `--features wayland,portal` | The GNOME Wayland Portal/EIS path has been checked for video and mouse/keyboard input on Ubuntu 26.04, GNOME 50, with one 4K screen at 200% scale; auto unlock after a cold locked connection is verified with the official Mac and iPhone 4.42.0 viewers, while other lock recovery and reconnection still need hardware acceptance testing. Apart from that path and GNOME on X11, desktop testing has primarily used virtual machines. If something goes wrong on -real hardware, please [open an issue](../../issues) with your distribution, desktop, GPU and the relevant lines from +real hardware, please [open an issue](../../issues) with the output of `uuremote-server doctor` (v0.2.17+; session, backend, +plugins, permissions and encoders only, no account data, tokens or addresses) and the relevant lines from `journalctl --user -u uuremote-native.service`. Wayland limits: captures one screen by default; Hyprland can enable monitor switching as described below. Resolution is fixed. The native Hyprland backend now pipelines two shm screencopy buffers and passes the viewer's requested fps to both capture pacing and the encoder. Actual fps remains limited by the compositor, rendering and readback (the old serial path measured about 16–22 fps at 2560x1600; the pipeline is VM-measured only, not a hardware guarantee). The portal backend does not support dynamic resolution; see below for GNOME wake and lock recovery; the clipboard syncs while the viewer's remote window has focus. On the first connection the desktop asks for "Remote Desktop / Screen Sharing" diff --git a/README.md b/README.md index 743dcd2..d3c79e1 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Portal 仅作用于本服务获授权的会话。文件传输、终端等独立 最后一列是源码编译方式;Release 预编译包已包含全部后端,直接使用即可(见[安装](#0-直接用-release-预编译包推荐x86_64))。 GNOME Wayland 的 Portal/EIS 路径已在 Ubuntu 26.04、GNOME 50、单屏 4K/200% 缩放下验证画面和键鼠;锁屏冷连接自动解锁已用 Mac 和 iPhone 4.42.0 客户端实机验证,其余锁屏恢复及重连仍待验收。除 GNOME 的上述路径和 X11 外,其余桌面目前主要在虚拟机里测试。如果你在真机上遇到问题,欢迎[提交 issue](../../issues), -请附上发行版、桌面环境、显卡型号和 `journalctl --user -u uuremote-native.service` 里的相关日志。 +请附上 `uuremote-server doctor` 的输出(v0.2.17 起;只含会话、后端、插件、权限、编码器等状态,不含账号、令牌或地址,可直接粘贴)和 `journalctl --user -u uuremote-native.service` 里的相关日志。 Wayland 下的限制:默认采集单屏,Hyprland 可按上文启用切屏;分辨率固定;Hyprland 原生后端默认使用双缓冲流水线 shm screencopy,控制端帧率设置会同步到采集节拍和编码器,但实际帧率仍受合成器、渲染和读回速度限制(旧串行路径在 2560x1600 曾测得约 16~22 帧;流水线只在虚拟机里测量过,不代表实机保证);portal 后端暂不支持动态分辨率;GNOME 的屏幕唤醒与锁屏恢复见下;剪贴板只在控制端的远控窗口处于前台时同步。 diff --git a/src/doctor.rs b/src/doctor.rs new file mode 100644 index 0000000..0eefb2d --- /dev/null +++ b/src/doctor.rs @@ -0,0 +1,134 @@ +//! `uuremote-server doctor`: one report with what an issue needs (session, backend, plugins, +//! input permission, encoders, config and service state), safe to paste publicly. It prints only +//! booleans, names and versions: no account ids, tokens, addresses, MACs or file contents, and the +//! home directory is shown as `~`. + +fn redact(text: &str) -> String { + let mut out = text.to_owned(); + if let Some(home) = std::env::var_os("HOME").and_then(|h| h.into_string().ok()).filter(|h| h.len() > 1) { out = out.replace(&home, "~"); } + if let Ok(user) = std::env::var("USER") { if user.len() > 2 { out = out.replace(&user, ""); } } + out +} + +fn env_state(name: &str) -> String { + match std::env::var(name) { Ok(v) if v.is_empty() => "set (empty)".into(), Ok(_) => "set".into(), Err(_) => "unset".into() } +} + +fn line(key: &str, value: impl std::fmt::Display) { println!("{key:<22} {}", redact(&value.to_string())); } + +fn glibc() -> String { + #[cfg(all(target_os = "linux", target_env = "gnu"))] + { + extern "C" { fn gnu_get_libc_version() -> *const libc::c_char; } + return unsafe { std::ffi::CStr::from_ptr(gnu_get_libc_version()) }.to_string_lossy().into_owned(); + } + #[allow(unreachable_code)] + "n/a".into() +} + +fn writable(path: &str) -> &'static str { + let Ok(c_path) = std::ffi::CString::new(path) else { return "invalid" }; + if !std::path::Path::new(path).exists() { "missing" } + else if unsafe { libc::access(c_path.as_ptr(), libc::W_OK) } == 0 { "writable" } else { "no permission" } +} + +async fn command_output(program: &str, args: &[&str]) -> Option { + let output = tokio::time::timeout(std::time::Duration::from_secs(5), + tokio::process::Command::new(program).args(args).kill_on_drop(true).output()).await.ok()?.ok()?; + Some(String::from_utf8_lossy(&output.stdout).trim().to_owned()) +} + +pub async fn run() -> Result<(), String> { + use crate::desktop_backend as backend; + use crate::engine_plugin::{load, Engine}; + println!("uu-remote-linux doctor (safe to paste: no ids, tokens, addresses or file contents)"); + line("version", format!("v{} {}", env!("CARGO_PKG_VERSION"), std::env::consts::ARCH)); + line("glibc", glibc()); + let os = std::fs::read_to_string("/etc/os-release").ok() + .and_then(|t| t.lines().find_map(|l| l.strip_prefix("PRETTY_NAME=").map(|v| v.trim_matches('"').to_owned()))); + line("os", os.unwrap_or_else(|| "unknown".into())); + let features: Vec<&str> = [("wayland", cfg!(feature = "wayland")), ("portal", cfg!(feature = "portal")), + ("engine-plugins", cfg!(feature = "engine-plugins")), ("inproc-av", cfg!(feature = "inproc-av"))] + .into_iter().filter(|(_, on)| *on).map(|(name, _)| name).collect(); + line("build features", if features.is_empty() { "default (X11 only)".to_owned() } else { features.join(", ") }); + + println!("-- session"); + line("XDG_SESSION_TYPE", std::env::var("XDG_SESSION_TYPE").unwrap_or_else(|_| "unset".into())); + line("XDG_CURRENT_DESKTOP", std::env::var("XDG_CURRENT_DESKTOP").unwrap_or_else(|_| "unset".into())); + line("DISPLAY", env_state("DISPLAY")); + line("WAYLAND_DISPLAY", env_state("WAYLAND_DISPLAY")); + line("wayland running", backend::wayland_session_running()); + line("UU_DESKTOP_BACKEND", std::env::var("UU_DESKTOP_BACKEND").unwrap_or_else(|_| "auto".into())); + let selected = backend::detect(); + line("selected backend", match &selected { Ok(b) if backend::headless() => format!("none (headless, {b:?} unused)"), Ok(b) => format!("{b:?}"), Err(e) => format!("error: {e}") }); + if selected.as_ref().is_ok_and(|b| *b == backend::DesktopBackend::X11) && backend::wayland_session_running() && !backend::headless() { + println!(" ! X11 backend inside a Wayland session: the picture will be black"); + } + if cfg!(feature = "engine-plugins") { + for engine in [Engine::Wayland, Engine::Portal] { + line(engine.file(), match load(engine) { Ok(()) => "loaded".to_owned(), Err(e) => e }); + } + } + + println!("-- input"); + line("/dev/uinput", writable("/dev/uinput")); + line("UU_INPUT_BACKEND", std::env::var("UU_INPUT_BACKEND").unwrap_or_else(|_| "auto".into())); + + println!("-- video"); + let encoder = crate::video::Encoder::requested(); + line("encoder", format!("{encoder:?} (UU_VIDEO_ENCODER={})", std::env::var("UU_VIDEO_ENCODER").unwrap_or_else(|_| "auto".into()))); + line("default codec", format!("{:?}", crate::capture_setting::preferred_codec(true, true))); + let mut ffmpeg = crate::video::ffmpeg_command(); + ffmpeg.args(["-hide_banner", "-encoders"]).kill_on_drop(true); + match tokio::time::timeout(std::time::Duration::from_secs(5), ffmpeg.output()).await { + Ok(Ok(output)) => { + let text = String::from_utf8_lossy(&output.stdout); + let found: Vec<&str> = ["libx264", "libx265", "h264_nvenc", "hevc_nvenc", "h264_vaapi", "hevc_vaapi"].into_iter() + .filter(|name| text.split_whitespace().any(|word| word == *name)).collect(); + line("ffmpeg encoders", if found.is_empty() { "none of libx264/libx265/nvenc/vaapi".to_owned() } else { found.join(", ") }); + } + _ => line("ffmpeg encoders", "ffmpeg not runnable (install ffmpeg or set ffmpeg_root)"), + } + let mut version = crate::video::ffmpeg_command(); + version.arg("-version").kill_on_drop(true); + if let Ok(Ok(output)) = tokio::time::timeout(std::time::Duration::from_secs(5), version.output()).await { + line("ffmpeg version", String::from_utf8_lossy(&output.stdout).lines().next().unwrap_or("").split_whitespace().nth(2).unwrap_or("unknown")); + } + line("nvidia driver", std::path::Path::new("/proc/driver/nvidia/version").exists()); + line("render node", writable(&std::env::var("UU_VAAPI_DEVICE").unwrap_or_else(|_| "/dev/dri/renderD128".into()))); + + println!("-- audio"); + for tool in ["pactl", "pw-cli"] { + line(tool, command_output("sh", &["-c", &format!("command -v {tool} >/dev/null && echo found || echo missing")]).await.unwrap_or_else(|| "unknown".into())); + } + + println!("-- account and service"); + let path = crate::config::path(); + line("config", path.display()); + match std::fs::metadata(&path) { + Ok(meta) => { + use std::os::unix::fs::PermissionsExt; + line("config mode", format!("{:o}", meta.permissions().mode() & 0o777)); + // Presence only: never read values out of the file. + let fields: Option = std::fs::read(&path).ok().and_then(|b| serde_json::from_slice(&b).ok()); + let has = |key: &str| fields.as_ref().and_then(|v| v.get(key)).is_some_and(|v| !v.is_null() && v.as_str() != Some("")); + line("signed in", has("token") && has("user_id")); + line("device registered", has("device_id")); + } + Err(_) => line("config mode", "missing (run `uuremote-server login`)"), + } + line("service", command_output("systemctl", &["--user", "is-active", "uuremote-native.service"]).await.unwrap_or_else(|| "systemctl unavailable".into())); + let running = command_output("pgrep", &["-c", "-x", "uuremote-server"]).await.filter(|n| !n.is_empty()).unwrap_or_else(|| "unknown".into()); + line("uuremote-server procs", format!("{running} (including this one; more than 2 means duplicates)")); + Ok(()) +} + +#[cfg(test)] +mod tests { + #[test] + fn redaction_hides_home_and_user() { + let home = std::env::var("HOME").unwrap_or_default(); + if home.len() > 1 { assert_eq!(super::redact(&format!("{home}/.config/x")), "~/.config/x"); } + assert_eq!(super::env_state("UU_DOCTOR_TEST_SURELY_UNSET"), "unset"); + } +} diff --git a/src/main.rs b/src/main.rs index e0c4ffb..b7e8819 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ //! Zero-Wine, Zero-Python, Single-Binary, 5 Native Tools Integrated mod engine_plugin; +mod doctor; mod desktop_backend; mod desktop_session; mod desktop_power; @@ -191,7 +192,7 @@ async fn main() -> Result<(), Box> { .filter_module("uuremote_server", log::LevelFilter::Info).init(); } else { env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init(); } // An unknown argument must never fall through to starting a second full host server. - const SUBCOMMANDS: [&str; 14] = ["show", "assist", "desktop-input-probe", "virtual-audio-probe", "login", "unlock-check", "desktop-probe", "desktop-video-probe", "desktop-audio-probe", "wayland-capture", + const SUBCOMMANDS: [&str; 15] = ["doctor", "show", "assist", "desktop-input-probe", "virtual-audio-probe", "login", "unlock-check", "desktop-probe", "desktop-video-probe", "desktop-audio-probe", "wayland-capture", "wayland-input-probe", "wayland-text-probe", "clipboard-acceptance", "portal-acceptance"]; if let Some(arg) = std::env::args().nth(1).filter(|a| !SUBCOMMANDS.contains(&a.as_str())) { let usage = format!("usage: uuremote-server [{}]\n (no argument: run the host)", SUBCOMMANDS.join(" | ")); @@ -357,6 +358,9 @@ async fn main() -> Result<(), Box> { if std::env::args().nth(1).as_deref() == Some("wayland-text-probe") { return wayland::text_probe().map_err(|e|e.into()); } + if std::env::args().nth(1).as_deref() == Some("doctor") { + return doctor::run().await.map_err(|e| e.into()); + } if std::env::args().nth(1).as_deref() == Some("wayland-capture") { return wayland::capture_stdout().map_err(|e| e.into()); }