226.2. kdos-boxsock-0.2.0
Per-launcher tagged Wayland socket in a box's private runtime directory — the security-context-v1 engine
| Version | 0.2.0, release 1 |
| Source tree | src/system/kdos-boxsock/ |
| Phase | 42_graphics (Graphics Stack), 166 of 189 in build order |
| Licence | MIT |
| Homepage | https://github.com/kunaldawn/kdos |
| Build time | 0.1 SBU |
| Installed size | 25.6 KiB in 1 file |
| Recipe | src/system/kdos-boxsock/kpkgbuild |
About
kdos-boxsock gives each launcher of a box its own Wayland socket, so KWin always knows which box a window comes from. It
- binds the socket in the box’s private runtime directory,
$XDG_RUNTIME_DIR/kdos/box/<box>/; - hands it to KWin through the
security-context-v1protocol, tagged with the launcher’s id as the app id, the box as the instance id and the engineio.kdos.appbox+privateorio.kdos.appbox+tagged; - prints
ready <path>; - stays alive, holding the descriptor that keeps the tag valid.
Every client that connects on that socket is tagged by KWin itself and never sees the tag, so it cannot forge or drop it. KWin’s sandbox filter and its grants (read by the instance id from the box’s profile), the window’s application id, the box’s title-bar colour rule and the sandbox badge all read that tag.
kdos-appbox starts one before it runs a launcher in a box and points the program’s WAYLAND_DISPLAY at the socket. When kdos-boxsock prints error <reason> instead, the box does not start and the reason is what the person sees.
It is a program of its own for two reasons: kdos-appbox run replaces itself with the container command, so it cannot hold the descriptor for the box’s lifetime, and kdos-appbox links no Wayland library. It is box infrastructure beside kdos-appbox and the boxes’ init, and links no toolkit. Its arguments, its lock and its exit codes are in The daemons.
Why it is in KDOS
The comment above it in script/phases/42_graphics/packages.d/src-system.txt:
The security-context-v1 sandbox engine: one tagged Wayland socket per box. Separate from kdos-appbox because
runexecs distrobox and cannot hold the context's close fd, and because kdos-appbox links no libraries.
Sources
None: the port builds from its own directory, /kdos/src/system/kdos-boxsock.
Dependencies
Depends on: wayland, wayland-protocols.
Required by (1): kdos-appbox.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/42_graphics/phase.env && kpkg install kdos-boxsock'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /kdos/src/system/kdos-boxsock.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/kdos-boxsock
SRC=$SRC_ROOT/kdos-boxsock-0.2.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
XML="$(pkg-config --variable=pkgdatadir wayland-protocols)/staging/security-context/security-context-v1.xml"
SCANNER="$(pkg-config --variable=wayland_scanner wayland-scanner)"
"$SCANNER" client-header "$XML" security-context-v1-client-protocol.h
"$SCANNER" private-code "$XML" security-context-v1-protocol.c
gcc $CFLAGS -O2 -Wall -Wextra \
-I. \
$(pkg-config --cflags wayland-client) \
-o kdos-boxsock "$PORT_SRC"/main.c security-context-v1-protocol.c \
$(pkg-config --libs wayland-client) $LDFLAGS
install -Dm755 kdos-boxsock "$PKG/usr/bin/kdos-boxsock"
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/kdos-boxsock, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf kdos-boxsock-0.2.0-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/kdos-boxsock, and runs the triggers its paths call for.
Other files in the port directory, read by build.sh: main.c.
Contents
Installed programs: kdos-boxsock.
Notes
- It uses none of KDOS’s own libraries. The build compiles
main.cwith the protocol codewayland-scannergenerates and linkswayland-client, nothing else. - The protocol comes from wayland-protocols’
staging/directory, found throughpkg-config --variable=pkgdatadir wayland-protocols. The scanner writes the client header and theprivate-codeglue into the work directory, and-I.is what letsmain.cinclude the header. - The compile line passes no
-D_GNU_SOURCE.main.cdefines it itself, guarded by#ifndef, becausetesting/selftest.shcompiles the same file with the define on its command line and-Werror, where an unguarded second definition is an error. - The socket’s path has to fit a Unix socket address, 108 bytes:
$XDG_RUNTIME_DIR/kdos/box/<box>/wl[.<stem>]@<display>. A box name long enough to overflow it is refused with that reason rather than bound under a shortened name the box could not find. - A launcher id differs from its box’s name by at most one dot-separated component. It is the box’s name itself, the box’s name plus one more component (a box with several launchers), or the box’s name less its last component (a throwaway box,
<launcher-id>.tw<n>, whose windows are its application’s). A launcher id further from its box is refused, because the id is the window’s identity in the Task Manager and KWin’s rules. - The lock is outside the private directory, at
$XDG_RUNTIME_DIR/kdos/box/.<box>.wl…lock, so nothing running in the box can take it and keep the socket from being served.