mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-16 08:50:40 +01:00
show: report a skipped or crash-looping service instead of waiting 30 s (#62); document FFmpeg 6.x for inproc-av (#63)
systemctl start returns 0 when the unit is skipped by a Condition or keeps crashing under Restart=; show now reads ActiveState/SubState/ConditionResult while waiting and names the real problem. ffmpeg-sys-next's build script runs before ours, so FFmpeg >= 7 cannot be caught in build.rs; the README and AGENTS state the 6.x requirement next to the build commands. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
03d2311649
commit
c1b8bfe1b3
4 files changed
+45
-3
No files matched your search
@@ -39,7 +39,8 @@ Dependencies (Ubuntu/Debian):
|
||||
sudo apt install build-essential pkg-config \
|
||||
libx11-dev libxext-dev libxtst-dev libxfixes-dev libavcodec-dev libavformat-dev libavdevice-dev libswscale-dev libclang-dev libgtk-3-dev ffmpeg
|
||||
# --features inproc-av: libavcodec-dev libavformat-dev libavdevice-dev libswscale-dev libclang-dev
|
||||
# (FFmpeg 6.x; in-process capture/encoding, Ubuntu 24.04 ships it)
|
||||
# (FFmpeg 6.x only; in-process capture/encoding, Ubuntu 24.04 ships it. FFmpeg >= 7
|
||||
# fails in ffmpeg-sys-next with "avfft.h file not found", before our build.rs runs)
|
||||
# --features wayland: libwayland-dev libxkbcommon-dev wl-clipboard
|
||||
# --features wayland,portal: + libglib2.0-dev libpipewire-0.3-dev libei-dev (libei >= 1.1)
|
||||
```
|
||||
|
||||
@@ -187,6 +187,11 @@ cargo build --release --features wayland # + Hyprland
|
||||
cargo build --release --features wayland,portal # + GNOME/KDE on Wayland
|
||||
```
|
||||
|
||||
The optional `--features inproc-av` (in-process encoding) and the viewer's `viewer-ffmpeg` support **FFmpeg 6.x only**
|
||||
(`pkg-config --modversion libavcodec` = 60.x). FFmpeg 7+ fails inside the `ffmpeg-sys-next` dependency with
|
||||
`avfft.h file not found`; its build script runs before this project's, so no clearer check is possible (#63). The default
|
||||
build and the release packages need neither feature.
|
||||
|
||||
### 3. Log in
|
||||
|
||||
Run inside your graphical session:
|
||||
|
||||
@@ -171,6 +171,10 @@ cargo build --release --features wayland # + Hyprland
|
||||
cargo build --release --features wayland,portal # + GNOME/KDE Wayland
|
||||
```
|
||||
|
||||
可选的 `--features inproc-av`(进程内编码)和控制端的 `viewer-ffmpeg` 只支持 **FFmpeg 6.x**(`pkg-config --modversion libavcodec` 为 60.x)。
|
||||
FFmpeg 7 及以上会在依赖 `ffmpeg-sys-next` 里报 `avfft.h file not found`——它的构建脚本先于本项目运行,所以无法提前给出更清楚的提示(#63)。
|
||||
默认构建和预编译包都不需要这两个特性。
|
||||
|
||||
### 3. 登录
|
||||
|
||||
在图形桌面里运行:
|
||||
|
||||
+34
-2
@@ -143,6 +143,35 @@ fn write_host_pid() {
|
||||
let _ = write!(f, "{}", std::process::id());
|
||||
}
|
||||
}
|
||||
/// Why `unit` is not (going to be) running, from `systemctl --user show`; None while it is active or starting.
|
||||
fn unit_not_running(unit: &str, settled: bool) -> Option<String> {
|
||||
let output = std::process::Command::new("systemctl").args(["--user", "show", unit, "-p", "ActiveState,SubState,ConditionResult"]).output().ok()?;
|
||||
let text = String::from_utf8_lossy(&output.stdout);
|
||||
let value = |key: &str| text.lines().find_map(|l| l.strip_prefix(key).and_then(|v| v.strip_prefix('='))).unwrap_or("").to_owned();
|
||||
unit_state_problem(unit, &value("ActiveState"), &value("SubState"), &value("ConditionResult"), settled)
|
||||
}
|
||||
fn unit_state_problem(unit: &str, active: &str, sub: &str, condition: &str, settled: bool) -> Option<String> {
|
||||
let hint = format!("see `systemctl --user status {unit}` and `journalctl --user -u {unit}`");
|
||||
if condition == "no" { return Some(format!("{unit} was skipped: a Condition in the unit is not met (e.g. ConditionEnvironment outside the graphical session); {hint}")); }
|
||||
if active == "failed" { return Some(format!("{unit} failed to start; {hint}")); }
|
||||
if sub == "auto-restart" { return Some(format!("{unit} keeps exiting and being restarted; {hint}")); }
|
||||
if settled && active == "inactive" { return Some(format!("{unit} is not running; {hint}")); }
|
||||
None
|
||||
}
|
||||
#[cfg(test)]
|
||||
mod show_unit_tests {
|
||||
#[test]
|
||||
fn skipped_crashing_and_failed_units_are_reported() {
|
||||
let p = |a, s, c, settled| super::unit_state_problem("u.service", a, s, c, settled);
|
||||
assert!(p("inactive", "dead", "no", false).unwrap().contains("skipped"));
|
||||
assert!(p("activating", "auto-restart", "yes", false).unwrap().contains("restarted"));
|
||||
assert!(p("failed", "failed", "yes", false).unwrap().contains("failed"));
|
||||
assert!(p("inactive", "dead", "yes", false).is_none());
|
||||
assert!(p("inactive", "dead", "yes", true).unwrap().contains("not running"));
|
||||
assert!(p("active", "running", "yes", true).is_none());
|
||||
assert!(p("activating", "start", "yes", true).is_none());
|
||||
}
|
||||
}
|
||||
/// `uuremote-server show` (desktop launcher): open the running host's window, or start the host in the
|
||||
/// foreground with its window when none runs (e.g. no systemd unit installed yet).
|
||||
fn show_running_host() -> Result<(), Box<dyn std::error::Error>> {
|
||||
@@ -162,7 +191,10 @@ fn show_running_host() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.stdout(std::process::Stdio::null()).stderr(std::process::Stdio::null()).status().is_ok_and(|s| s.success());
|
||||
if installed && std::process::Command::new("systemctl").args(["--user", "start", &unit]).status().is_ok_and(|s| s.success()) {
|
||||
let before = std::fs::metadata(host_pid_path()).and_then(|m| m.modified()).ok();
|
||||
for _ in 0..60 {
|
||||
for attempt in 0..60 {
|
||||
// `systemctl start` also returns 0 when the unit is skipped by a Condition or keeps
|
||||
// crashing under Restart=; report that instead of waiting 30 s for a pid (#62).
|
||||
if let Some(reason) = unit_not_running(&unit, attempt >= 2) { return Err(reason.into()); }
|
||||
std::thread::sleep(std::time::Duration::from_millis(500));
|
||||
let fresh = std::fs::metadata(host_pid_path()).and_then(|m| m.modified()).ok().is_some_and(|t| Some(t) != before);
|
||||
let pid = std::fs::read_to_string(host_pid_path()).ok().and_then(|s| s.trim().parse::<i32>().ok());
|
||||
@@ -171,7 +203,7 @@ fn show_running_host() -> Result<(), Box<dyn std::error::Error>> {
|
||||
if unsafe { libc::kill(pid, libc::SIGUSR1) } == 0 { return Ok(()); }
|
||||
}
|
||||
}
|
||||
return Err("the UU remote host service started but did not open its window".into());
|
||||
return Err(format!("{unit} is running but did not open its window within 30 s; check `journalctl --user -u {unit}`").into());
|
||||
}
|
||||
use std::os::unix::process::CommandExt;
|
||||
Err(Box::new(std::process::Command::new("/proc/self/exe").env("UU_SHOW_WINDOW", "1").exec()))
|
||||
|
||||
Reference in new issue
Block a user