Files
chandra/session/chandra-ctl
T
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

135 lines
5.0 KiB
Python
Executable File

#!/usr/bin/env python3
"""chandra-ctl: talk to a running Chandra compositor over its control socket.
chandra-ctl reload load every panel module again from disk
chandra-ctl reload NAME only the module(s) whose name, slot or path is NAME
chandra-ctl list the loaded panel modules: slot, module, path
chandra-ctl ping check the compositor answers
chandra-ctl shortcut ID do what a keyboard shortcut does (overview, launcher, show-desktop...)
chandra-ctl kiosk [lock|unlock|status] kiosk mode (--kiosk, docs/kiosk.md)
chandra-ctl launch ID start desktop app ID (org.kde.kwi) as the dock does
chandra-ctl windows how Chandra sees each window, and what is under the pointer
chandra-ctl auth-demo [MODE] show the password dialog with a pretend check (password "demo");
MODE: password, face, face-ok, die, slow, users (docs/auth-dialog.md)
chandra-ctl auth-status the password dialog's agent: registered with polkit, or why not
The socket is $XDG_RUNTIME_DIR/chandra/<wayland socket name>.sock (the session's is
wayland-moon-0.sock). It is found in this order: --socket PATH, $CHANDRA_CONTROL, the one for
$WAYLAND_DISPLAY, else the only socket in $XDG_RUNTIME_DIR/chandra. Prints the compositor's reply;
exits 0 when it ends in "ok", 1 on "error", 2 when no compositor could be reached.
See docs/reloading.md.
"""
import glob
import os
import socket
import sys
USAGE = "usage: chandra-ctl [--socket PATH] [--quiet] {reload [NAME] | list | ping | shortcut ID | kiosk [lock|unlock|status] | launch ID | windows | auth-demo [MODE] | auth-status | help}"
def runtime_dir():
d = os.environ.get("XDG_RUNTIME_DIR", "")
if d:
return d
d = "/run/user/%d" % os.getuid()
return d if os.path.isdir(d) else ""
def find_socket(explicit):
if explicit:
return explicit
env = os.environ.get("CHANDRA_CONTROL", "")
if env:
return env
rt = runtime_dir()
if not rt:
sys.exit("chandra-ctl: XDG_RUNTIME_DIR is not set; pass --socket PATH")
base = os.path.join(rt, "chandra")
wd = os.environ.get("WAYLAND_DISPLAY", "")
if wd:
p = os.path.join(base, os.path.basename(wd) + ".sock")
if os.path.exists(p):
return p
socks = sorted(glob.glob(os.path.join(base, "*.sock")))
if len(socks) == 1:
return socks[0]
if not socks:
print("chandra-ctl: no control socket in %s (is a Chandra session running a build "
"with the control socket? it needs one restart after installing it)" % base,
file=sys.stderr)
sys.exit(2)
print("chandra-ctl: several compositors are running; pick one with --socket:", file=sys.stderr)
for s in socks:
print(" " + s, file=sys.stderr)
sys.exit(2)
def main(argv):
explicit = ""
quiet = False
args = []
i = 0
while i < len(argv):
a = argv[i]
if a == "--socket" and i + 1 < len(argv):
explicit = argv[i + 1]
i += 2
continue
if a.startswith("--socket="):
explicit = a.split("=", 1)[1]
elif a in ("-q", "--quiet"):
quiet = True
elif a in ("-h", "--help"):
print(__doc__.strip())
return 0
else:
args.append(a)
i += 1
if not args:
print(USAGE, file=sys.stderr)
return 2
command = " ".join(args)
if "\n" in command:
print("chandra-ctl: one command at a time", file=sys.stderr)
return 2
path = find_socket(explicit)
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.settimeout(30) # reloading every module takes about a second
try:
s.connect(path)
except OSError as e:
print("chandra-ctl: can't connect to %s: %s" % (path, e.strerror or e), file=sys.stderr)
return 2
s.sendall((command + "\n").encode())
s.shutdown(socket.SHUT_WR)
data = b""
try:
while True:
chunk = s.recv(4096)
if not chunk:
break
data += chunk
# The reply ends with its "ok ..." / "error ..." line.
lines = data.decode("utf-8", "replace").splitlines()
if data.endswith(b"\n") and lines and (lines[-1].startswith("ok") or lines[-1].startswith("error")):
break
except socket.timeout:
print("chandra-ctl: no reply from %s" % path, file=sys.stderr)
return 2
finally:
s.close()
lines = data.decode("utf-8", "replace").splitlines()
if not lines:
print("chandra-ctl: the compositor closed the connection without a reply", file=sys.stderr)
return 2
last = lines[-1]
for l in lines:
if quiet and l is not last:
continue
print(l, file=sys.stderr if l.startswith("error") or l.startswith("failed") else sys.stdout)
return 0 if last.startswith("ok") else 1
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))