From 7bf0cc02ed3323224e0cfc19cfe9118990bae729 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Fri, 17 May 2019 13:43:10 +1200 Subject: Allow explicitly selecting DRM devices --- drm_info.h | 2 +- json.c | 28 ++++++++++++++++++++-------- main.c | 4 ++-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/drm_info.h b/drm_info.h index 7c7fa98..654440a 100644 --- a/drm_info.h +++ b/drm_info.h @@ -3,7 +3,7 @@ struct json_object; -struct json_object *drm_info(void); +struct json_object *drm_info(char *paths[]); void print_drm(struct json_object *obj); #endif diff --git a/json.c b/json.c index ee82aaf..5960dae 100644 --- a/json.c +++ b/json.c @@ -603,18 +603,30 @@ static struct json_object *node_info(const char *path) return obj; } -struct json_object *drm_info(void) +/* paths is a NULL terminated argv array */ +struct json_object *drm_info(char *paths[]) { struct json_object *obj = json_object_new_object(); - 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; + /* 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; - struct json_object *dev = node_info(path); - json_object_object_add(obj, path, dev); + struct json_object *dev = node_info(path); + json_object_object_add(obj, path, dev); + } + } else { + for (char **path = paths; *path; ++path) { + struct json_object *dev = node_info(*path); + if (!dev) + continue; + + json_object_object_add(obj, *path, dev); + } } return obj; diff --git a/main.c b/main.c index b404192..1b2650e 100644 --- a/main.c +++ b/main.c @@ -19,12 +19,12 @@ int main(int argc, char *argv[]) json = true; break; default: - fprintf(stderr, "usage: drm_info [-j]\n"); + fprintf(stderr, "usage: drm_info [-j] [--] [path]...\n"); exit(opt == '?' ? EXIT_SUCCESS : EXIT_FAILURE); } } - struct json_object *obj = drm_info(); + struct json_object *obj = drm_info(&argv[optind]); if (json) { json_object_to_fd(STDOUT_FILENO, obj, JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED); -- cgit v1.2.3