fix(linux): drop implicit DRM master for card fds (#5286)
Co-authored-by: Kishi85 <41839133+Kishi85@users.noreply.github.com>
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#pragma once
|
||||
|
||||
// standard includes
|
||||
#include <fcntl.h>
|
||||
#include <filesystem>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
@@ -45,3 +47,24 @@ namespace dyn {
|
||||
void *handle(const std::vector<const char *> &libs);
|
||||
|
||||
} // namespace dyn
|
||||
|
||||
namespace platf {
|
||||
/**
|
||||
* @brief Open a DRM card node and drop implicit DRM master, if any.
|
||||
*
|
||||
* Performs `open(path, flags | O_CLOEXEC)` and probes the resulting fd with
|
||||
* `DRM_IOCTL_AUTH_MAGIC`. If the kernel implicitly handed us master, calls
|
||||
* `drmDropMaster` and re-verifies before returning. Master check/drop failures
|
||||
* are logged as warnings but do not fail the call: the caller still receives
|
||||
* a usable fd.
|
||||
*
|
||||
* Callers should use this helper for any `/dev/dri/cardN` open so we never
|
||||
* keep implicit master and block compositors from re-acquiring it on VT
|
||||
* switches.
|
||||
*
|
||||
* @param path Path to the DRM card node (e.g. `/dev/dri/card0`).
|
||||
* @param flags `open()` flags. `O_CLOEXEC` is always OR-ed in.
|
||||
* @return A file descriptor on success, or `-1` if `open()` itself fails.
|
||||
*/
|
||||
int open_drm_card_fd(const std::filesystem::path &path, int flags = O_RDWR);
|
||||
} // namespace platf
|
||||
|
||||
Reference in New Issue
Block a user