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
@@ -253,6 +253,15 @@ pub fn spawn(cmd : String, display : String) -> Bool {
|
||||
c_spawn(str_to_utf8_bytes(cmd), str_to_utf8_bytes(display)) == 0
|
||||
}
|
||||
|
||||
///|
|
||||
extern "C" fn c_take_sigusr1() -> Int = "mp_take_sigusr1"
|
||||
|
||||
///| True once after the process got SIGUSR1 (reload the panel modules). The first call installs
|
||||
/// the handler; a signal interrupts `wait_readable`, so an idle loop wakes for it.
|
||||
pub fn take_sigusr1() -> Bool {
|
||||
c_take_sigusr1() != 0
|
||||
}
|
||||
|
||||
///|
|
||||
extern "C" fn c_list_desktop(dir : Bytes) -> Bytes = "mp_list_desktop"
|
||||
|
||||
|
||||
@@ -347,6 +347,35 @@ void mp_sleep_ms(int32_t ms) {
|
||||
}
|
||||
}
|
||||
|
||||
/* SIGUSR1: reload the panel modules (compositor/host/control.mbt). The handler only sets a
|
||||
* flag; it is installed without SA_RESTART, so a blocked poll() returns EINTR and the main loop
|
||||
* runs a pass. */
|
||||
static volatile sig_atomic_t mp_sigusr1_seen = 0;
|
||||
static int mp_sigusr1_installed = 0;
|
||||
|
||||
static void mp_on_sigusr1(int sig) {
|
||||
(void)sig;
|
||||
mp_sigusr1_seen = 1;
|
||||
}
|
||||
|
||||
MOONBIT_FFI_EXPORT
|
||||
int32_t mp_take_sigusr1(void) {
|
||||
if (!mp_sigusr1_installed) {
|
||||
struct sigaction sa;
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_handler = mp_on_sigusr1;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = 0;
|
||||
sigaction(SIGUSR1, &sa, NULL);
|
||||
mp_sigusr1_installed = 1;
|
||||
}
|
||||
if (mp_sigusr1_seen) {
|
||||
mp_sigusr1_seen = 0;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
MOONBIT_FFI_EXPORT
|
||||
int32_t mp_getpid(void) {
|
||||
return (int32_t)getpid();
|
||||
|
||||
@@ -198,6 +198,11 @@ pub fn spawn(cmd : String, display : String) -> Bool {
|
||||
@hostsys.spawn(cmd, display)
|
||||
}
|
||||
|
||||
///| True once after the host process got SIGUSR1 (reload the panel modules).
|
||||
pub fn take_sigusr1() -> Bool {
|
||||
@hostsys.take_sigusr1()
|
||||
}
|
||||
|
||||
///| Names of the `*.desktop` files directly in `dir`.
|
||||
pub fn list_desktop_files(dir : String) -> Array[String] {
|
||||
@hostsys.list_desktop_files(dir)
|
||||
|
||||
Reference in new issue
Block a user