From 869e789a645b92a99e592a230fe39b0c59a2cd7d Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 11 Jun 2019 21:45:41 +0300 Subject: Use drmGetDevices to list nodes There's no guarantee that DRM primary nodes start at card0. I've run into a system where the first card is card1 (probably because the driver has been unloaded/reloaded?). Because of this drm_info wasn't dumping any data. Instead, we can use drmGetDevices which returns a list of DRM devices and nodes available on the system. --- json.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/json.c b/json.c index 24b662c..c6ff1c7 100644 --- a/json.c +++ b/json.c @@ -628,18 +628,28 @@ struct json_object *drm_info(char *paths[]) /* Print everything by default */ if (!paths[0]) { - char path[PATH_MAX]; - for (int i = 0;; ++i) { - snprintf(path, sizeof path, DRM_DEV_NAME, DRM_DIR_NAME, i); - if (access(path, R_OK) < 0) - break; + drmDevice *devices[64]; + int n = drmGetDevices(devices, sizeof(devices) / sizeof(devices[0])); + if (n < 0) { + perror("drmGetDevices"); + json_object_put(obj); + return NULL; + } - struct json_object *dev = node_info(path); - if (!dev) + for (int i = 0; i < n; ++i) { + drmDevice *dev = devices[i]; + if (!(dev->available_nodes & (1 << DRM_NODE_PRIMARY))) continue; - json_object_object_add(obj, path, dev); + const char *path = dev->nodes[DRM_NODE_PRIMARY]; + struct json_object *dev_obj = node_info(path); + if (!dev_obj) + continue; + + json_object_object_add(obj, path, dev_obj); } + + drmFreeDevices(devices, n); } else { for (char **path = paths; *path; ++path) { struct json_object *dev = node_info(*path); -- cgit v1.2.3