Files
RedBear-OS/local/recipes/system/redbear-session-launch
vasilito cb424d7448 build: static patch-sanity linter (shift-left the malformed-patch class)
verify-patch-sanity.py validates every active recipe .patch has internally-
consistent hunk line counts — catching the 'malformed patch at line N' failure
at commit/CI/preflight time instead of hours into a cook. This cycle hit that
class three times (qtwaylandscanner, sddm, xwayland), each only discovered when
cookbook tried to apply the patch.

Running it across the repo found 29 latent malformed patches (validated against
GNU patch: e.g. relibc/P3-sysv-ipc reproduces 'malformed patch at line 22').
They were harmless only because they sit in vendored recipes (baked, not re-
applied) — but would fail on any version-bump re-derivation. --fix recounts the
hunk headers (body untouched) and repaired all 29.

Wired into build-preflight.sh (Phase 1.0D) and redbear-ci.yml, with a unit test
(test-patch-sanity.sh). Skips archived/legacy trees and unvalidatable formats
(empty placeholders, bare-@@ git hunks).
2026-08-01 05:13:02 +03:00
..

redbear-session-launch

Session bootstrap helper — uid/gid/env/runtime-dir handoff

Status: FEATURE-INCOMPLETE Category: system Build: cargo build --release --manifest-path source/Cargo.toml

Purpose

redbear-session-launch is the Red Bear session bootstrap binary. It loads a user account from /etc/passwd, resolves supplementary group memberships from /etc/group, creates an XDG-compliant runtime directory with correct ownership, builds a full desktop environment variable set, and then exec()s into the target session command (KDE on Wayland) or an arbitrary program with the correct uid/gid/supplementary groups. It is invoked by redbear-authd after successful authentication and by redbear-greeterd to launch the compositor and greeter UI as the greeter user.

Command Line

redbear-session-launch --username USER [--mode session|command] [--session kde-wayland]
    [--vt N] [--runtime-dir PATH] [--wayland-display NAME]
    [--command PROGRAM [ARGS...]]
Flag Description
--username USER Required. User to launch as.
`--mode session command`
--session NAME Session type (currently only kde-wayland is supported). Sets XDG_CURRENT_DESKTOP=KDE.
--vt N Virtual terminal number (default: 3).
--runtime-dir PATH Override the XDG runtime directory (default: /run/user/<uid> or /tmp/run/user/<uid>).
--wayland-display NAME Wayland display socket name (default: wayland-0).
--command PROGRAM [ARGS...] In command mode, the program and arguments to execute.

Architecture

Single-file Rust binary (src/main.rs, ~609 lines). No async runtime — synchronous execution model culminating in exec().

Key types:

  • Account — username, uid, gid, home directory, shell
  • GroupEntry — gid + member usernames
  • LaunchModeSession or Command { program, args }
  • Args — parsed CLI arguments

Flow:

  1. Parse CLI arguments
  2. Load account from /etc/passwd (dual-format: Redox ; + Unix :)
  3. Load supplementary groups from /etc/group (intersection of primary gid and group memberships)
  4. Create XDG runtime directory with mkdir + chown + chmod 700
  5. Build environment map:
    • Standard: HOME, USER, LOGNAME, SHELL, PATH
    • XDG: XDG_CONFIG_HOME, XDG_CACHE_HOME, XDG_STATE_HOME, XDG_RUNTIME_DIR, XDG_CURRENT_DESKTOP, XDG_SESSION_TYPE, XDG_SESSION_ID
    • Wayland: WAYLAND_DISPLAY
    • KDE: KDE_FULL_SESSION=true
    • Seat: LIBSEAT_BACKEND=seatd, SEATD_SOCK=/run/seatd.sock
    • Propagated: KWIN_DRM_DEVICES, XCURSOR_THEME, XKB_CONFIG_ROOT, QT_PLUGIN_PATH, REDBEAR_DRM_WAIT_SECONDS
  6. Build command: for session mode → /usr/bin/dbus-run-session -- /usr/bin/redbear-kde-session (or direct if dbus-run-session missing)
  7. exec() with uid()/gid() setters + pre_exec for setgroups() (Linux host only; Redox target omits setgroups since the syscall is not yet implemented)

Dependencies: libc only.

Status Notes

  • Core functionality: Account loading, supplementary group resolution, runtime directory creation, environment setup, command selection, and exec() handoff all implemented.
  • Session types: Only kde-wayland is supported. Other session names return an error.
  • Dual-format parsing: Supports both Redox (;) and Unix (:) account file formats.
  • setgroups: Applied on Linux host only. Redox target omits the call (redox_syscall SYS_SETGROUPS not yet implemented).
  • Tests: 11 unit tests covering CLI parsing (session mode, command mode, error cases), passwd parsing (Unix + Redox formats), group parsing, environment construction (session + command modes), KWIN_DRM_DEVICES propagation, and unsupported session names.

Consumers

  • redbear-authd — launches user desktop sessions after successful authentication
  • redbear-greeterd — launches greeter compositor and UI as the greeter user

Cross-reference: local/docs/GREETER-LOGIN-IMPLEMENTATION-PLAN.md