Files
Claude 50149e6b99
CI / test (push) Canceled after 17m11s
Launches that fail say why: command, exit status and what it printed
V: "kwi not starting from app menu or dock". Kwi is a Flatpak, and bwrap died
before it opened a window ("Can't find source path /run/user/1000/doc/by-app/
org.kde.kwi"); Chandra forked apps and forgot them, so the failure only reached
the session log and the click did nothing visible.

Every app the Applications menu, the dock, Super+1..9 and session restore start
now runs under a small monitor (sys spawn-watch, compositor/sys/sys_stub.c): it
copies the app's output to the session log as before, keeps its last 2 KiB,
and reports how sh -c CMD exited on a socket the main loop wakes on. The shell
(compositor/shell/launch.mbt) shows a red error notice for 15 s, and logs it,
when the app exits non-zero or by a signal within 30 s, or exits 0 without ever
opening a window here (after a 2 s grace for single-instance hand-offs): the
first line says what happened, then the command and the last lines it printed,
repeats folded ("(3 times)"). Status 127/126 say "command not found" / "not
executable". Launched apps no longer inherit the compositor's fds.

chandra-ctl launch ID starts a desktop app exactly as the dock does.

Tests: compositor/host/launch_test.mbt (bwrap-style failure incl. drawn notice,
127, SIGSEGV, exit 0 without a window, an app that keeps running), unit tests
in launch.mbt. Checked end to end with build/wasmhost + compositor.wasm
headless and a Flatpak-style kwi desktop file: chandra-ctl launch org.kde.kwi
shows the notice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hiGJWeuHiTgtoyB4kb
2026-11-26 05:48:39 +00:00

221 lines
5.5 KiB
MoonBit

///| `chandra:host/sys`: the OS surface, over compositor/sys's native implementation (the same
/// C shim the native compositor uses).
///|
#borrow(path, data)
extern "C" fn c_append_file(path : Bytes, data : Bytes) -> Int = "wh_append_file"
///| Fds beyond the first that arrived with the last `recvmsg` on a socket, for `take-fd`.
let extra_fds : Map[Int, Array[Int]] = {}
///|
fn drop_extra_fds(sock : Int) -> Unit {
match extra_fds.get(sock) {
Some(left) => {
for f in left {
@sys.close_fd(f)
}
extra_fds.remove(sock)
}
None => ()
}
}
///|
fn s32(v : Int) -> Array[@wt.Val] {
[S32(v)]
}
///|
fn boolean(b : Bool) -> Array[@wt.Val] {
[Bool(b)]
}
///|
let none : Array[@wt.Val] = []
///|
fn sys_funcs() -> Array[(String, (Array[@wt.Val]) -> Array[@wt.Val])] {
[
("unix-listen", a => s32(@sys.unix_listen(a[0].to_string()))),
("unix-accept", a => s32(@sys.unix_accept(a[0].to_int()))),
("unix-connect", a => s32(@sys.unix_connect(a[0].to_string()))),
(
"close-fd",
a => {
let fd = a[0].to_int()
if fd >= 0 {
// A closed client socket's number is reused by the next one: drop what it left.
drop_extra_fds(fd)
@sys.close_fd(fd)
}
none
},
),
(
"unlink",
a => {
@sys.unlink(a[0].to_string())
none
},
),
("poll-read", a => s32(@sys.poll_read(a[0].to_int(), a[1].to_int()))),
(
"wait-readable",
a => {
let fds = a[0].to_list().map(v => v.to_int())
for f in display_wait_fds() {
fds.push(f)
}
s32(@sys.wait_readable(fds, a[1].to_int()))
},
),
(
"recvmsg",
a => {
let fd = a[0].to_int()
// Fds from the previous read nobody took would leak: close them.
drop_extra_fds(fd)
let max_len = a[1].to_int()
let received = fn(count : Int, got : Int, data : Bytes) -> Array[@wt.Val] {
[
Record([
("count", S32(count)),
("fd", S32(got)),
("data", @wt.Val::bytes(data)),
]),
]
}
if max_len <= 0 {
return received(0, -1, b"")
}
let buf = FixedArray::make(max_len, b'\x00')
let (n, fds) = @sys.recvmsg_fds(fd, buf, max_len)
if n < 0 {
for f in fds {
@sys.close_fd(f)
}
return received(n, -1, b"")
}
let got = if fds.length() > 0 { fds[0] } else { -1 }
if fds.length() > 1 {
extra_fds.set(fd, fds[1:].to_array())
}
received(n, got, Bytes::from_fixedarray(buf, len=n))
},
),
(
"take-fd",
a => {
let sock = a[0].to_int()
match extra_fds.get(sock) {
Some(q) if q.length() > 0 => {
let f = q.remove(0)
if q.length() == 0 {
extra_fds.remove(sock)
}
s32(f)
}
_ => s32(-1)
}
},
),
(
"sendmsg",
a => {
let data = a[1].to_bytes()
if data.length() == 0 {
return s32(0)
}
s32(@sys.sendmsg_fd(a[0].to_int(), data, a[2].to_int()))
},
),
("memfd-create", a => s32(@sys.memfd_create(a[0].to_string(), a[1].to_int()))),
(
"pwrite",
a => {
let fd = a[0].to_int()
let data = a[1].to_bytes()
let off = a[2].to_int()
s32(
if off < 0 {
@sys.write_nonblock(fd, data)
} else {
@sys.pwrite_bytes(fd, data, off)
},
)
},
),
(
"mmap-read",
a => [@wt.Val::bytes(@sys.mmap_read(a[0].to_int(), a[1].to_int()))],
),
(
"mmap-read-at",
a => {
let (fd, off, len) = (a[0].to_int(), a[1].to_int(), a[2].to_int())
if fd < 0 || off < 0 || len <= 0 {
return [@wt.Val::bytes(b"")]
}
[@wt.Val::bytes(@sys.mmap_read_at(fd, off, len))]
},
),
(
"read-file",
a => [@wt.Val::bytes(@sys.read_file_bytes(a[0].to_string()))],
),
(
"write-file",
a => s32(@sys.write_file_bytes(a[0].to_string(), a[1].to_bytes())),
),
(
"append-file",
a => s32(c_append_file(@utf8.encode(a[0].to_string()), a[1].to_bytes())),
),
(
"read-proc",
a => [@wt.Val::bytes(@sys.read_proc_bytes(a[0].to_string()))],
),
("mkdir-p", a => boolean(@sys.mkdir_p(a[0].to_string()))),
(
"list-desktop-files",
a => [@wt.Val::strings(@sys.list_desktop_files(a[0].to_string()))],
),
(
"sleep-ms",
a => {
let ms = a[0].to_int()
if ms > 0 {
@sys.sleep_ms(ms)
}
none
},
),
("monotonic-ms", _ => [U64(@sys.monotonic_ms())]),
(
"log",
a => {
eprint(a[0].to_string())
none
},
),
("getpid", _ => s32(@sys.getpid())),
("take-sigusr1", _ => boolean(@sys.take_sigusr1())),
("wall-time-field", a => s32(@sys.wall_time_field(a[0].to_int()))),
("getenv", a => [Str(@sys.getenv(a[0].to_string()))]),
("has-exe", a => boolean(@sys.has_exe(a[0].to_string()))),
(
"spawn",
a => boolean(@sys.spawn(a[0].to_string(), a[1].to_string())),
),
(
"spawn-watch",
a => s32(@sys.spawn_watch(a[0].to_string(), a[1].to_string())),
),
(
"spawn-socket",
a => s32(@sys.spawn_socket(a[0].to_string().split("\n").map(v => v.to_string()).to_array())),
),
]
}