drm: Follow symlinks for AQ_DRM_DEVICES (#34)

This commit is contained in:
Samuel Cobb 2024-07-26 12:17:06 +01:00 committed by GitHub
parent 0ab8ffa67d
commit f95d150937
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,6 +8,8 @@
#include <thread> #include <thread>
#include <deque> #include <deque>
#include <cstring> #include <cstring>
#include <filesystem>
#include <system_error>
#include <sys/mman.h> #include <sys/mman.h>
#include <fcntl.h> #include <fcntl.h>
@ -135,6 +137,22 @@ static std::vector<SP<CSessionDevice>> scanGPUs(SP<CBackend> backend) {
backend->log(AQ_LOG_DEBUG, std::format("drm: Explicit device list {}", explicitGpus)); backend->log(AQ_LOG_DEBUG, std::format("drm: Explicit device list {}", explicitGpus));
Hyprutils::String::CVarList explicitDevices(explicitGpus, 0, ':', true); Hyprutils::String::CVarList explicitDevices(explicitGpus, 0, ':', true);
// Iterate over GPUs and canonicalize the paths
for (auto& d : explicitDevices) {
std::error_code ec;
auto canonicalFilePath = std::filesystem::canonical(d, ec);
// If there is an error, log and continue.
// TODO: Verify that the path is a valid DRM device. (https://gitlab.freedesktop.org/wlroots/wlroots/-/blob/master/backend/session/session.c?ref_type=heads#L369-387)
if (ec) {
backend->log(AQ_LOG_ERROR, std::format("drm: Failed to canonicalize path {}", d));
continue;
}
d = canonicalFilePath.string();
}
for (auto& d : explicitDevices) { for (auto& d : explicitDevices) {
bool found = false; bool found = false;
for (auto& vd : devices) { for (auto& vd : devices) {