Reload panel modules from outside the session: control socket, chandra-ctl, SIGUSR1
CI / test (push) Failing after 16s
CI / test (push) Failing after 16s
Until now a module reload was only reachable by clicking Settings > Panel inside the session. Now: - The compositor listens on $XDG_RUNTIME_DIR/chandra/<wayland socket name>.sock (the login session's is wayland-moon-0.sock) with a line protocol: ping, list, reload [NAME], help. Replies end with an "ok ..." or "error ..." line. It lives in compositor/host/control.mbt, runs from ChandraCompositor::step, and its fds join the idle loop's wait set, so an idle desktop still sleeps (measured ~0.4% CPU on wasmhost, ~0.1% on host-wasm) and wakes for a command. A path another live compositor answers on is left alone. - DesktopShell::reload_modules(name) reloads every loaded module (or those whose module id, stem, slot or path is NAME) in place via replace_slot: same panel position, saved :module-config applied, a module that fails to load stays as it was and the error is reported to the caller and shown as a notice. The catalog is rescanned. - SIGUSR1 to the host reloads every module (result in the log and the notice): new WIT function sys.take-sigusr1, implemented in compositor/sys (native build and wasmhost) and host-wasm; the handler has no SA_RESTART so it interrupts the idle poll. - session/chandra-ctl (installed to /usr/local/bin), `just reload [NAME]`, docs/reloading.md, README. - Tests: compositor/host/control_test.mbt (protocol, reload all / by name / by slot, order and settings kept, failing module kept, busy socket). Checked headless on both hosts with chandra-ctl and kill -USR1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hjLJtvYcgW48okL6qQ
This commit is contained in:
21 files changed
+844
-31
No files matched your search
@@ -9,6 +9,7 @@
|
||||
//! chandra-host build/compositor.wasm --socket /run/user/1000/wayland-moon-0 --window
|
||||
|
||||
use std::ffi::CString;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::io::Read;
|
||||
use std::os::unix::process::CommandExt;
|
||||
use std::process::{Command, Stdio};
|
||||
@@ -36,6 +37,11 @@ wasmtime::component::bindgen!({
|
||||
use chandra::host::font::Glyph;
|
||||
use chandra::host::sys::{Host, Received};
|
||||
|
||||
/// SIGUSR1 (reload the panel modules) arrived and not yet taken by sys.take-sigusr1; whether
|
||||
/// its handler is installed.
|
||||
static SIGUSR1_SEEN: AtomicBool = AtomicBool::new(false);
|
||||
static SIGUSR1_INSTALLED: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
#[derive(Default)]
|
||||
struct State {
|
||||
/// Address of the private session bus launched apps use (started on first spawn).
|
||||
@@ -900,6 +906,24 @@ impl Host for State {
|
||||
std::process::id() as i32
|
||||
}
|
||||
|
||||
fn take_sigusr1(&mut self) -> bool {
|
||||
// The handler only sets a flag. No SA_RESTART: a blocked poll() in wait-readable returns
|
||||
// EINTR, so an idle compositor runs a pass and sees the request.
|
||||
extern "C" fn on_sigusr1(_: libc::c_int) {
|
||||
SIGUSR1_SEEN.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
}
|
||||
if !SIGUSR1_INSTALLED.swap(true, std::sync::atomic::Ordering::SeqCst) {
|
||||
unsafe {
|
||||
let mut sa: libc::sigaction = std::mem::zeroed();
|
||||
sa.sa_sigaction = on_sigusr1 as extern "C" fn(libc::c_int) as usize;
|
||||
libc::sigemptyset(&mut sa.sa_mask);
|
||||
sa.sa_flags = 0;
|
||||
libc::sigaction(libc::SIGUSR1, &sa, std::ptr::null_mut());
|
||||
}
|
||||
}
|
||||
SIGUSR1_SEEN.swap(false, std::sync::atomic::Ordering::SeqCst)
|
||||
}
|
||||
|
||||
fn wall_time_field(&mut self, which: i32) -> i32 {
|
||||
unsafe {
|
||||
let t = libc::time(std::ptr::null_mut());
|
||||
|
||||
Reference in new issue
Block a user