- char *udev_test;
- char *temp;
- int retval;
-
- udev_test = getenv("UDEV_TEST");
- if (udev_test == NULL) {
- /* normal operation, use the compiled in defaults */
- udev_config_dir = UDEV_CONFIG_DIR;
- udev_root = UDEV_ROOT;
- retval = sysfs_get_mnt_path(sysfs_path, SYSFS_PATH_MAX);
- dbg("sysfs_path = %s", sysfs_path);
- if (retval)
- dbg("sysfs_get_mnt_path failed");
-
- } else {
- /* hm testing is happening, use the specified values */
- temp = getenv("UDEV_SYSFS_PATH");
- strncpy(sysfs_path, temp, sizeof(sysfs_path));
- udev_config_dir = getenv("UDEV_CONFIG_DIR");
- udev_root = getenv("UDEV_ROOT");
+ static const char short_options[] = "q:rVh";
+ int option;
+ int retval = -EINVAL;
+ struct udevice dev;
+
+ while (1) {
+ option = getopt(argc, argv, short_options);
+ if (option == -1)
+ break;
+
+ dbg("option '%c'", option);
+ switch (option) {
+ case 'q':
+ dbg("udev query: %s\n", optarg);
+ retval = udevdb_open_ro();
+ if (retval != 0) {
+ printf("unable to open udev database\n");
+ return -1;
+ }
+ retval = udevdb_get_dev(optarg, &dev);
+ if (retval == 0) {
+ printf("%s\n", dev.name);
+ } else {
+ printf("device not found in udev database\n");
+ }
+ udevdb_exit();
+ return retval;
+
+ case 'r':
+ printf("%s\n", udev_root);
+ return 0;
+
+ case 'V':
+ printf("udev, version %s\n", UDEV_VERSION);
+ return 0;
+
+ case 'h':
+ retval = 0;
+ case '?':
+ default:
+ goto help;
+ }