mirror of
https://github.com/marcoallegretti/WEFT_OS.git
synced 2026-11-22 08:13:59 +00:00
fix(appd): keep the previous session when shutdown interrupts its restore
The session file is read and removed at startup, and restoring now runs in its own task, so a shutdown during the restore would have saved only the apps launched so far. Until the restore finishes, a shutdown stops it and saves the restored list unchanged.
This commit is contained in:
parent
2e27adc4f6
commit
db042fcb5c
2 changed files with 17 additions and 7 deletions
|
|
@ -217,11 +217,13 @@ async fn run() -> anyhow::Result<()> {
|
||||||
let _ = sd_notify::notify(false, &[sd_notify::NotifyState::Ready]);
|
let _ = sd_notify::notify(false, &[sd_notify::NotifyState::Ready]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(app_ids) = load_session() {
|
// Restoring runs beside the request loops, so waiting for the
|
||||||
// Restoring runs beside the request loops, so waiting for the
|
// compositor delays neither clients nor shutdown. Until it finishes,
|
||||||
// compositor delays neither clients nor shutdown.
|
// the restored list is what a shutdown saves.
|
||||||
|
let restore = load_session().map(|app_ids| {
|
||||||
|
let saved = app_ids.clone();
|
||||||
let registry = Arc::clone(®istry);
|
let registry = Arc::clone(®istry);
|
||||||
tokio::spawn(async move {
|
let task = tokio::spawn(async move {
|
||||||
// Apps need the compositor connection; give it a moment.
|
// Apps need the compositor connection; give it a moment.
|
||||||
let compositor = registry.lock().await.compositor_tx.clone();
|
let compositor = registry.lock().await.compositor_tx.clone();
|
||||||
if let Some(compositor) = compositor {
|
if let Some(compositor) = compositor {
|
||||||
|
|
@ -242,7 +244,8 @@ async fn run() -> anyhow::Result<()> {
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
(task, saved)
|
||||||
|
});
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
let mut sigterm = {
|
let mut sigterm = {
|
||||||
|
|
@ -288,7 +291,14 @@ async fn run() -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
save_session(registry.lock().await.running_app_ids()).await;
|
let app_ids = match restore {
|
||||||
|
Some((task, saved)) if !task.is_finished() => {
|
||||||
|
task.abort();
|
||||||
|
saved
|
||||||
|
}
|
||||||
|
_ => registry.lock().await.running_app_ids(),
|
||||||
|
};
|
||||||
|
save_session(app_ids).await;
|
||||||
registry.lock().await.shutdown_all();
|
registry.lock().await.shutdown_all();
|
||||||
tokio::time::sleep(tokio::time::Duration::from_millis(200)).await;
|
tokio::time::sleep(tokio::time::Duration::from_millis(200)).await;
|
||||||
let _ = std::fs::remove_file(&socket_path);
|
let _ = std::fs::remove_file(&socket_path);
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ For verified read-only package storage, `weft-pack build-image` produces an EROF
|
||||||
|
|
||||||
## Wayland Surface Isolation
|
## Wayland Surface Isolation
|
||||||
|
|
||||||
Each app shell is given exactly one Wayland connection, created for its session. weft-appd creates a connected socket pair, gives one end to the app shell as its standard input with `WAYLAND_SOCKET=0` and no `WAYLAND_DISPLAY`, and sends the other end to the compositor over the compositor IPC socket (`SCM_RIGHTS`) with the session ID and app ID. The compositor adds that end as a client bound to the session; the binding comes from appd holding the connection, never from an ID or process ID the client supplies. A session's `zweft_shell` windows carry the session's app ID whatever the client requests, and the shell-only `panel` and `overlay` roles are refused with a protocol error; layer-shell surfaces and the input-method interface are not offered to session clients at all. When the session ends, the compositor closes its client; when the client disconnects, the compositor reports it to appd; when appd's connection ends, the compositor closes every session client appd attached. The compositor accepts one appd connection at a time. A launch is refused (503) while appd is not connected to the compositor, rather than starting an app that could never show a window; if the connection drops between that check and the app shell's start, the session is stopped before the app shell starts. Frames for appd that its socket cannot take at once are queued and retried; a backlog beyond 4 MiB, from an appd that stopped reading, ends the connection and with it the sessions' clients.
|
Each app shell is given exactly one Wayland connection, created for its session. weft-appd creates a connected socket pair, gives one end to the app shell as its standard input with `WAYLAND_SOCKET=0` and no `WAYLAND_DISPLAY`, and sends the other end to the compositor over the compositor IPC socket (`SCM_RIGHTS`) with the session ID and app ID. The compositor adds that end as a client bound to the session; the binding comes from appd holding the connection, never from an ID or process ID the client supplies. A session's `zweft_shell` windows carry the session's app ID whatever the client requests, and the shell-only `panel` and `overlay` roles are refused with a protocol error; layer-shell surfaces and the input-method interface are not offered to session clients at all. When the session ends, the compositor closes its client; when the client disconnects, the compositor reports it to appd; when appd's connection ends, the compositor closes every session client appd attached. The compositor accepts one appd connection at a time. A launch is refused (503) while appd is not connected to the compositor, rather than starting an app that could never show a window; if the compositor connection is lost before the session's connection is handed over, the session is stopped before the app shell starts. Frames for appd that its socket cannot take at once are queued and retried; a backlog beyond 4 MiB, from an appd that stopped reading, ends the connection and with it the sessions' clients.
|
||||||
|
|
||||||
Not yet covered: the compositor IPC socket accepts any process of the user while no appd is connected, so the first connection after a restart is trusted as appd; window placement, stacking, focus and close are not yet decided by the compositor per session (all toplevels start at the origin); and the trusted system shell is identified only by connecting through the display socket, which any process of the user, including an app shell, can open.
|
Not yet covered: the compositor IPC socket accepts any process of the user while no appd is connected, so the first connection after a restart is trusted as appd; window placement, stacking, focus and close are not yet decided by the compositor per session (all toplevels start at the origin); and the trusted system shell is identified only by connecting through the display socket, which any process of the user, including an app shell, can open.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue