`dmabuf_t::init_gbm()` opens the render node and hands the descriptor to
`gbm_create_device()`; the destructor destroys the GBM device but never
closes the descriptor, on the assumption that GBM owns it. It does not:
libgbm leaves the fd to the caller (`gbm_device_destroy()` does not close
it).
Every capture (re)initialisation constructs a new `dmabuf_t` -- one per
streaming session start, plus one per output mode change and per encoder
validation pass that reaches a real capture -- so the process keeps one
open `/dev/dri/renderD*` descriptor per (re)init for its lifetime.
Measured on a long-running host (Hyprland, `capture = wlr`, `encoder =
nvenc`, NVIDIA 610.57.04, v2026.516.143833; unchanged on master):
`/dev/dri` descriptors went 4 -> 8 across three Moonlight connect /
disconnect cycles and only a restart of Sunshine returned them.
Own the descriptor together with the device in a small RAII type,
`wl::gbm_device_t`, whose `reset()` destroys the device and then closes
the descriptor (and which closes it when device creation fails); open it
with `O_CLOEXEC` so prep/do commands do not inherit it. The open/create/
destroy calls are injectable (`gbm_device_accessors_t`, same shape as
`gbm_bo_accessors_t`) so the lifecycle is covered by unit tests that need
no GPU: the descriptor is closed on reset, on the failure path and on
destruction.
Signed-off-by: Raphael Derosso Pereira <raphael@insignis.com.br>
Sanitize GUI loader and plugin environment variables before privileged initialization, failing closed when the environment cannot be cleaned.
Retain CAP_SYS_ADMIN only on a dedicated DRM worker, route KMS and CUDA DRM access through it, reject queued work safely during overflow or shutdown, and drop the worker privileges when DRM access is no longer needed.
Add Linux regression coverage for the sanitizer and document the new privileged-worker interfaces.
Co-authored-by: Conn O'Griofa <749000+psyke83@users.noreply.github.com>
Co-authored-by: Kishi <41839133+Kishi85@users.noreply.github.com>