Files
RedBear-OS/local/recipes/system/redbear-sessiond
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-sessiond

Session manager daemon — D-Bus login1 subset for KWin/Wayland

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

Purpose

redbear-sessiond provides a Red Bear-native implementation of the org.freedesktop.login1 D-Bus interface on the system bus. It exposes Manager, Session, and Seat objects that KWin, SDDM, and other Wayland/KDE components expect during the desktop session lifecycle. It replaces systemd-logind with a pure-Rust, zbus-based daemon that integrates directly with Red Bear's ACPI scheme and device filesystem layout.

D-Bus Interface

  • Bus: system
  • Well-known name: org.freedesktop.login1
  • Object paths:
    • /org/freedesktop/login1 — Manager
    • /org/freedesktop/login1/session/c1 — Session
    • /org/freedesktop/login1/seat/seat0 — Seat
    • /org/freedesktop/login1/user/current — User

Manager Interface (org.freedesktop.login1.Manager)

Method Description
ListSessions Returns current session list (uid, username, seat, path)
GetSession(id) Resolves session ID to object path
GetSessionByPID(pid) Resolves PID to session path
ListSeats Returns seat list
GetSeat(id) Resolves seat ID to object path
ListUsers Returns user list (uid, username, path)
GetUser(uid) Resolves UID to user object path
ListInhibitors Lists active sleep/shutdown inhibitors
Inhibit(what, who, why, mode) Registers a shutdown/sleep inhibitor; returns FD
PowerOff(interactive) Writes "shutdown" to /scheme/sys/kstop
Reboot(interactive) Writes "reset" to /scheme/sys/kstop
Suspend(interactive) Writes "s3" to /scheme/sys/kstop
CanPowerOff / CanReboot / CanSuspend Returns "yes" when /scheme/sys/kstop is writable, "na" otherwise
CanHibernate / CanHybridSleep / CanSuspendThenHibernate / CanSleep Returns "na" (not yet implemented)
ActivateSession(id) Activates a session
ActivateSessionOnSeat(id, seat) Activates a session on a specific seat
LockSession / UnlockSession Set/clear locked hint on a session
LockSessions / UnlockSessions Lock/unlock all sessions
TerminateSession(id) Sets session state to "closing"
TerminateUser(uid) Sets session state to "closing" for user
KillSession(id, who, signal) Sends signal to session leader PID
KillUser(uid, signal) Sends signal to user's session leader PID

Properties: IdleHint, IdleSinceHint, IdleSinceHintMonotonic, BlockInhibited, DelayInhibited, InhibitDelayMaxUSec, HandleLidSwitch, HandlePowerKey, PreparingForSleep, PreparingForShutdown

Signals: PrepareForSleep(before: bool), PrepareForShutdown(before: bool), SeatNew, SeatRemoved

Session Interface (org.freedesktop.login1.Session)

Methods: Activate, TakeControl, ReleaseControl, TakeDevice(major, minor), ReleaseDevice(major, minor), PauseDeviceComplete, SetIdleHint, SetLockedHint, SetType, Terminate, Kill

Properties: Active, Remote, Type, Class ("user"), Service ("redbear"), Desktop ("KDE"), Display, Id, State, Seat, User, VTNr, Leader, Audit, TTY, RemoteUser, RemoteHost, IdleHint, LockedHint

Signals: PauseDevice(major, minor, kind), ResumeDevice(major, minor, fd), Lock, Unlock

Seat Interface (org.freedesktop.login1.Seat)

Methods: SwitchTo(vt) — delegates to inputd -A <vt>

Properties: Id, ActiveSession, Sessions, CanGraphical (true), CanTTY (true), IdleHint

Architecture

8 Rust modules composing a single binary:

Module Purpose
main.rs Entry point, argument parsing, D-Bus connection with retry, shutdown signal handling
manager.rs LoginManager — all Manager interface methods, inhibitor lifecycle, signal emission
session.rs LoginSession — all Session interface methods, device control, PauseDevice/ResumeDevice signals
seat.rs LoginSeat — all Seat interface methods, VT switching via inputd
runtime_state.rs SessionRuntime — shared state (session ID, username, UID, VT, inhibitors, idle/lock hints) behind Arc<RwLock<>>
control.rs JSON-over-Unix-socket control channel at /run/redbear-sessiond-control.sock — accepts set_session, reset_session, shutdown, set_inhibit_delay, set_lid_switch, set_power_key, set_last_activity messages
acpi_watcher.rs ACPI edge watcher — polls scheme:kernel.acpi/kstop for shutdown (verb 2) and sleep (verb 3) edges; emits PrepareForShutdown/PrepareForSleep D-Bus signals
device_map.rs (major, minor) → scheme path resolution cache — scans /scheme/drm/, /dev/input/, /dev/fb* at startup; supports lazy single-device resolution and periodic refresh; fallback paths for common major numbers (13=evdev, 226=drm, 29=fb)

Dependencies: zbus v5, tokio (multi-thread runtime), serde/serde_json, libc, libredox, redox_syscall. Uses a vendored tokio patch with Redox-specific epoll recovery for early-boot scheme churn.

Consumers

  • KWin (reads login1 session/seat state via D-Bus)
  • SDDM (registers sessions)
  • redbear-authd (sends set_session / reset_session control messages)
  • KDE Plasma (monitors idle hint, lock state, session lifecycle)

Status Notes

  • login1 Manager interface: 32+ methods implemented. PowerOff/Reboot/Suspend write to /scheme/sys/kstop (Redox kernel stop scheme). Hibernate/sleep variants return "na" until kernel support lands.
  • Inhibitor lifecycle: Fully implemented with Unix pipe FDs. Caller holds one end; daemon holds the other. Caller-closed FDs trigger automatic inhibitor reaping. Background reaper polls NameHasOwner every 2s to detect vanished bus names.
  • Device map: Filesystem-based (major, minor) resolution with no hardcoded entries. Supports lazy resolution via scan_single() and fallback path generation for common device classes.
  • ACPI watcher: On Redox, polls scheme:kernel.acpi/kstop for shutdown/sleep edges. On host (Linux), returns immediately — integration tests exercise the D-Bus signal plumbing without the kernel side.
  • Tests: 30+ unit tests covering manager, session, seat, control message parsing, inhibitor lifecycle, idle/lock hints, and property defaults.
  • Runtime state: Thread-safe behind Arc<RwLock<SessionRuntime>> with manual Clone impl for consistent snapshots.

Cross-reference: local/docs/DBUS-INTEGRATION-PLAN.md