@@ -9,6 +9,7 @@ namespace fs = std::filesystem;
99using namespace std ::chrono_literals;
1010
1111FDInfoBase::FDInfoBase (const std::string& drm_node, const pid_t pid) : drm_node(drm_node), pid(pid) {
12+ card_node = get_card_node ();
1213 init ();
1314}
1415
@@ -72,10 +73,10 @@ std::vector<std::string> FDInfoBase::find_fds() {
7273 continue ;
7374 }
7475
76+ // comparison to both renderD* and card* is required because
7577 // for some reason supertuxkart opens /dev/dri/card and not renderD
7678 // inside podman container.
77- // this is only for testing, so remove it later
78- if (link.filename () != drm_node && link.string ().substr (0 , 13 ) != " /dev/dri/card" )
79+ if (link.filename () != drm_node && link.filename () != card_node)
7980 continue ;
8081
8182 fds.push_back (entry.path ().filename ());
@@ -121,6 +122,29 @@ void FDInfoBase::open_fds(const std::vector<std::string>& fds) {
121122 SPDLOG_DEBUG (" Received {} ids, opened {} unique ids" , fds.size (), total);
122123}
123124
125+ std::string FDInfoBase::get_card_node () {
126+ const std::string device = " /sys/class/drm/" + drm_node + " /device/drm" ;
127+
128+ if (!std::filesystem::exists (device)) {
129+ SPDLOG_DEBUG (" drm dir doesn't exist for {}" , drm_node);
130+ return " " ;
131+ }
132+
133+ // Find first dir which starts with name "card"
134+ for (const auto & entry : fs::directory_iterator (device)) {
135+ std::filesystem::path path = entry.path ();
136+
137+ if (path.filename ().string ().substr (0 , 4 ) == " card" ) {
138+ const std::string filename = path.filename ();
139+ SPDLOG_DEBUG (" found card node for {}: {}" , drm_node, filename);
140+ return filename;
141+ }
142+ }
143+
144+ SPDLOG_DEBUG (" didn't find card node for {}" , drm_node);
145+ return " " ;
146+ }
147+
124148void FDInfoWrapper::add_pid (pid_t pid) {
125149 std::unique_lock lock (pids_mutex);
126150
0 commit comments