X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev%2Fudevinfo.c;h=6501b57d1a48958dd396f8af0f75cb4b4bc570fc;hp=b9ee17c4f1012651fae6ba36bf1e9e3c8eddce37;hb=742f4cad0d7c4af0a5d27ac6597be7410fa127e6;hpb=726687ad48bdececed1e7e44387c50e009e28208 diff --git a/udev/udevinfo.c b/udev/udevinfo.c index b9ee17c4f..6501b57d1 100644 --- a/udev/udevinfo.c +++ b/udev/udevinfo.c @@ -16,6 +16,8 @@ * */ +#include "config.h" + #include #include #include @@ -155,7 +157,7 @@ static void export_db(void) { list_for_each_entry(name_loop, &name_list, node) { struct udevice *udev_db; - udev_db = udev_device_init(NULL); + udev_db = udev_device_init(); if (udev_db == NULL) continue; if (udev_db_get_device(udev_db, name_loop->name) == 0) @@ -166,7 +168,7 @@ static void export_db(void) { name_list_cleanup(&name_list); } -static int lookup_device_by_name(struct udevice *udev, const char *name) +static int lookup_device_by_name(struct udevice **udev, const char *name) { LIST_HEAD(name_list); int count; @@ -181,26 +183,32 @@ static int lookup_device_by_name(struct udevice *udev, const char *name) /* select the device that seems to match */ list_for_each_entry(device, &name_list, node) { + struct udevice *udev_loop; char filename[PATH_SIZE]; struct stat statbuf; - udev_device_init(udev); - if (udev_db_get_device(udev, device->name) != 0) - continue; + udev_loop = udev_device_init(); + if (udev_loop == NULL) + break; + if (udev_db_get_device(udev_loop, device->name) != 0) + goto next; info("found db entry '%s'\n", device->name); - /* make sure, we don't get a link of a differnt device */ + /* make sure, we don't get a link of a different device */ strlcpy(filename, udev_root, sizeof(filename)); strlcat(filename, "/", sizeof(filename)); strlcat(filename, name, sizeof(filename)); if (stat(filename, &statbuf) != 0) - continue; - if (major(udev->devt) > 0 && udev->devt != statbuf.st_rdev) { - info("skip '%s', dev_t doesn't match\n", udev->name); - continue; + goto next; + if (major(udev_loop->devt) > 0 && udev_loop->devt != statbuf.st_rdev) { + info("skip '%s', dev_t doesn't match\n", udev_loop->name); + goto next; } rc = 0; + *udev = udev_loop; break; +next: + udev_device_cleanup(udev_loop); } out: name_list_cleanup(&name_list); @@ -222,14 +230,14 @@ static int stat_device(const char *name, int export, const char *prefix) prefix, major(statbuf.st_dev), prefix, minor(statbuf.st_dev)); } else - printf("%d %d\n", major(statbuf.st_dev), minor(statbuf.st_dev)); + printf("%d:%d\n", major(statbuf.st_dev), minor(statbuf.st_dev)); return 0; } -int udevinfo(int argc, char *argv[], char *envp[]) +int udevinfo(int argc, char *argv[]) { int option; - struct udevice *udev; + struct udevice *udev = NULL; int root = 0; int export = 0; const char *export_prefix = NULL; @@ -275,12 +283,6 @@ int udevinfo(int argc, char *argv[], char *envp[]) udev_config_init(); sysfs_init(); - udev = udev_device_init(NULL); - if (udev == NULL) { - rc = 1; - goto exit; - } - while (1) { option = getopt_long(argc, argv, "aed:n:p:q:rxPVh", options, NULL); if (option == -1) @@ -373,10 +375,10 @@ int udevinfo(int argc, char *argv[], char *envp[]) export_prefix = optarg; break; case 1: - printf("%s\n", UDEV_VERSION); + printf("%s\n", VERSION); goto exit; case 'V': - printf("udevinfo, version %s\n", UDEV_VERSION); + printf("udevinfo, version %s\n", VERSION); goto exit; case 'h': printf("Usage: udevadm info OPTIONS\n" @@ -406,13 +408,18 @@ int udevinfo(int argc, char *argv[], char *envp[]) case ACTION_QUERY: /* needs devpath or node/symlink name for query */ if (path[0] != '\0') { + udev = udev_device_init(); + if (udev == NULL) { + rc = 1; + goto exit; + } if (udev_db_get_device(udev, path) != 0) { fprintf(stderr, "no record for '%s' in database\n", path); rc = 3; goto exit; } } else if (name[0] != '\0') { - if (lookup_device_by_name(udev, name) != 0) { + if (lookup_device_by_name(&udev, name) != 0) { fprintf(stderr, "node name not found\n"); rc = 4; goto exit; @@ -463,7 +470,7 @@ int udevinfo(int argc, char *argv[], char *envp[]) goto exit; } } else if (name[0] != '\0') { - if (lookup_device_by_name(udev, name) != 0) { + if (lookup_device_by_name(&udev, name) != 0) { fprintf(stderr, "node name not found\n"); rc = 4; goto exit;