diff options
author | Scott Anderson <scott@anderso.nz> | 2019-05-17 13:43:10 +1200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2019-05-17 08:59:49 +0300 |
commit | 7bf0cc02ed3323224e0cfc19cfe9118990bae729 (patch) | |
tree | e9746326a59d860b45e319dde4aaa0261bcaee48 | |
parent | 27a9e3b5696d0ced9117e61d074ab1396d3113eb (diff) | |
download | external_drm_info-7bf0cc02ed3323224e0cfc19cfe9118990bae729.tar.gz external_drm_info-7bf0cc02ed3323224e0cfc19cfe9118990bae729.tar.bz2 external_drm_info-7bf0cc02ed3323224e0cfc19cfe9118990bae729.zip |
Allow explicitly selecting DRM devices
-rw-r--r-- | drm_info.h | 2 | ||||
-rw-r--r-- | json.c | 28 | ||||
-rw-r--r-- | main.c | 4 |
3 files changed, 23 insertions, 11 deletions
@@ -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 @@ -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; @@ -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); |