The Termux client and the APatch core communicate over the broker’s Unix sockets. The Go client keeps the existing wire format.
Requests (client → broker → core)
Send one plain JSON object terminated by \n. No type byte comes before the request. The CLI translates login into run with a login shell:
{"cmd":"run","args":{"name":"ubuntu","command":["/bin/bash","-l"],"hardened":true}}
A PTY session may then send raw input bytes after the core acknowledges {"ok":true,"data":{"pid":...}}. Waiting for the acknowledgement keeps input from being consumed as part of the initial JSON request. desktop --check doesn’t forward input.
Responses (core → broker → client)
| Type | Format | Meaning |
|---|---|---|
0x01 | 4-byte big-endian length + bytes | Raw PTY output |
0x02 | JSON + \n | Acknowledgement, progress, result, or error |
- Simple commands get
{"ok":true,"data":{...}}or{"ok":false,"error":"..."}. install/convertcan send{"phase":"layer","detail":"1/3 ..."}before the final result.run/desktopget the PID acknowledgement, optional0x01frames, then{"ok":true,"data":{"exit":0}}(or a framed error). EOF or a reset before the exit status is not success. The client closes the socket once it gets a final result; it does not replay requests on a dropped connection.
The client also accepts the earlier broker’s unframed JSON error when no core is available, to ease upgrades.
Commands
cmd | args | Response |
|---|---|---|
ping | — | {uid, pid, version, just_updated} |
info | — | host capability probes |
install | {image, name?} | progress → {installed, rootfs} |
convert | {name, as_name?, move?} | progress → {converted, moved, image} |
run | {name, command, ...} | PID → PTY output → {exit} |
desktop | {name, user?, as_root, check, shared_audio, min_free_mib?} | PID → PTY output → {exit} |
exec | {name, command, ...} | {exit, stdout, stderr} |
list / stats | — | {containers: [...]} |
ports | — | {ip, ports: [...]} |
remove | {name} | {removed} |
kill | {name} | {killed} |
clone | {src, dst} | {cloned, entries} |
push / pull | {name, src, dest} | {copied, to} |
service | {name, verb, unit?} | {exit, stdout, stderr} |
setuser | {name, user} | {name, user} |
shutdown | — | core exits (internal command) |
Broker and sockets
The broker pairs a CLI connection with one of the core’s idle connections and relays bytes both ways. It skips disconnected relays and returns a 0x02 error if a core isn’t available. The core doesn’t send a handshake on its sockets.
| Socket | Owner | Who connects |
|---|---|---|
.../tmp/apatch-chroot-broker.sock | Termux uid (app_data_file) | the CLI |
.../tmp/apatch-chroot-core.sock | Termux uid (app_data_file) | the root core |
Both sockets stay in Termux’s private app storage so the app can reach the broker without gaining access to a root-owned socket. See Architecture for the SELinux reason behind this design.