aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Anderson <scott@anderso.nz>2019-05-17 13:43:10 +1200
committerSimon Ser <contact@emersion.fr>2019-05-17 08:59:49 +0300
commit7bf0cc02ed3323224e0cfc19cfe9118990bae729 (patch)
treee9746326a59d860b45e319dde4aaa0261bcaee48
parent27a9e3b5696d0ced9117e61d074ab1396d3113eb (diff)
downloadexternal_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.h2
-rw-r--r--json.c28
-rw-r--r--main.c4
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);