fix(host): APPIMAGE is believed only when this program runs from that image
The AppImage launcher sets APPIMAGE (the image's file) and APPDIR (where
it is mounted) for the program it starts, and every program that one
starts inherits both: a terminal, an editor, an agent's app. The host's
start, the agent's pointer file, the host's check for a replaced program
and `update` each read APPIMAGE and believed it whenever it named a file.
So a wanderbooks run from inside another app's AppImage took that app's
image for its own:
- it started that image as the host, and the books never opened ("the
books server keeps failing to start");
- `connect` would have written that image into the agent's pointer file;
- `wanderbooks update` replaced that app's file with wanderbooks.
Found by the batch's gate: the_host_outlives_the_app_scope_that_started_it
passes its own environment on (the other tests clear it), and this gate
ran in a session started from an AppImage app. The first and the third
are reproduced by two new tests, which fail without this change (the
update test read an ELF header where the other app's file had been).
The rule now (start.rs INVARIANT 6, from the AppImage documentation's
"Environment variables"): the image is this program's own only when
APPIMAGE is an absolute file, APPDIR an absolute folder, and the running
executable's file is inside APPDIR, compared as resolved paths. One
function decides (`own_appimage`), and all four readers ask it. The host
is handed APPDIR beside APPIMAGE, and neither unless both are its own.
No books and no figure are touched. The tests that pretend to be an
AppImage now set APPDIR as a launcher does; translocation.rs used a bare
APPIMAGE to stand in for a macOS path, the very thing this closes, and
names the program's folder as the mount.
The failing test's message now lists the lines that did arrive, which is
what showed the host was refused rather than slow.
Not checked against a built AppImage (none has been built with this
change): the first trial of one shows `update` and a restart find the
image.
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
0178809a3d
commit
3bc198594b
12 files changed
+331
-52
No files matched your search
@@ -254,12 +254,16 @@ impl Running {
|
||||
/// Wait for a line containing `text`.
|
||||
fn expect(&self, text: &str, secs: u64) -> String {
|
||||
let deadline = Instant::now() + Duration::from_secs(secs);
|
||||
let mut seen = Vec::new();
|
||||
loop {
|
||||
let left = deadline.saturating_duration_since(Instant::now());
|
||||
match self.lines.recv_timeout(left) {
|
||||
Ok(line) if line.contains(text) => return line,
|
||||
Ok(_) => {}
|
||||
Err(_) => panic!("no line with {text:?} in {secs} s"),
|
||||
Ok(line) => seen.push(line),
|
||||
// What did arrive says why: a refusal, or nothing at all.
|
||||
Err(e) => {
|
||||
panic!("no line with {text:?} in {secs} s ({e}); the lines seen: {seen:?}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1203,6 +1207,43 @@ fn books_commands_hold_the_books_while_they_run() {
|
||||
}
|
||||
}
|
||||
|
||||
/// start.rs INVARIANT 6: started from inside another app's AppImage (a
|
||||
/// terminal, an editor, an agent's app: each hands `APPIMAGE` and `APPDIR`
|
||||
/// to everything it starts), this program is still the one that runs as
|
||||
/// the host. That image is never run.
|
||||
#[test]
|
||||
fn another_apps_appimage_is_never_run_as_the_host() {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
let home = Home::new("foreign");
|
||||
// The other app: a program that leaves a mark if it is ever run.
|
||||
let mark = home.dir.path().join("other-app-ran");
|
||||
let other = home.dir.path().join("Other.AppImage");
|
||||
std::fs::write(&other, format!("#!/bin/sh\n: > '{}'\n", mark.display())).unwrap();
|
||||
std::fs::set_permissions(&other, std::fs::Permissions::from_mode(0o755)).unwrap();
|
||||
let mount = home.dir.path().join("other-mount");
|
||||
std::fs::create_dir(&mount).unwrap();
|
||||
let mut c = home.cmd("books");
|
||||
c.args(["create", "acme"])
|
||||
.env("APPIMAGE", &other)
|
||||
.env("APPDIR", &mount)
|
||||
.stdin(Stdio::null());
|
||||
let out = c.output().unwrap();
|
||||
assert!(out.status.success(), "{out:?}");
|
||||
let mut c = home.cmd("serve");
|
||||
c.env("APPIMAGE", &other).env("APPDIR", &mount);
|
||||
let held = Running::start(c);
|
||||
held.expect("The books are open", 30);
|
||||
let host = home.host().unwrap();
|
||||
assert_eq!(
|
||||
std::fs::read_link(format!("/proc/{host}/exe")).unwrap(),
|
||||
std::fs::canonicalize(&home.exe).unwrap(),
|
||||
"the host is another program"
|
||||
);
|
||||
assert!(!mark.exists(), "the other app's image was run");
|
||||
held.signal(libc::SIGINT);
|
||||
assert!(home.wait_closed(10));
|
||||
}
|
||||
|
||||
/// Under a systemd app scope (as uwsm sets up), closing the app that
|
||||
/// started the host leaves the host for the other holders. Run only where
|
||||
/// a systemd user manager is there to make scopes.
|
||||
|
||||
Reference in new issue
Block a user