X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fudev%2Fudevadm-hwdb.c;h=ca1bf165a963a930fcbd301711c830568e97a2b4;hb=82c1d8f4eb74ddd9be2c9b9b56d9dc564c599eff;hp=fd288db1cb73d68cf162743b46c0ca807225e0b1;hpb=ee623f0d0c04a9c8da4953ddc29862c8c4945458;p=elogind.git diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c index fd288db1c..ca1bf165a 100644 --- a/src/udev/udevadm-hwdb.c +++ b/src/udev/udevadm-hwdb.c @@ -469,20 +469,23 @@ static int import_file(struct trie *trie, const char *filename) { } static void help(void) { - printf("Usage: udevadm hwdb [--create] [--help]\n" + printf("Usage: udevadm hwdb OPTIONS\n" " --update update the hardware database\n" - " --test query database and print result\n" + " --test= query database and print result\n" + " --root= alternative root path in the filesystem\n" " --help\n\n"); } static int adm_hwdb(struct udev *udev, int argc, char *argv[]) { static const struct option options[] = { { "update", no_argument, NULL, 'u' }, + { "root", required_argument, NULL, 'r' }, { "test", required_argument, NULL, 't' }, { "help", no_argument, NULL, 'h' }, {} }; const char *test = NULL; + const char *root = ""; bool update = false; struct trie *trie = NULL; int err; @@ -491,7 +494,7 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) { for (;;) { int option; - option = getopt_long(argc, argv, "ut:h", options, NULL); + option = getopt_long(argc, argv, "ut:r:h", options, NULL); if (option == -1) break; @@ -502,6 +505,9 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) { case 't': test = optarg; break; + case 'r': + root = optarg; + break; case 'h': help(); return EXIT_SUCCESS; @@ -515,6 +521,7 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) { if (update) { char **files, **f; + _cleanup_free_ char *hwdb_bin = NULL; trie = calloc(sizeof(struct trie), 1); if (!trie) { @@ -537,7 +544,7 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) { } trie->nodes_count++; - err = conf_files_list_strv(&files, ".hwdb", (const char **)conf_file_dirs); + err = conf_files_list_strv(&files, ".hwdb", root, (const char **)conf_file_dirs); if (err < 0) { log_error("failed to enumerate hwdb files: %s\n", strerror(-err)); rc = EXIT_FAILURE; @@ -565,11 +572,14 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) { log_debug("strings dedup'ed: %8zu bytes (%8zu)\n", trie->strings->dedup_len, trie->strings->dedup_count); - mkdir_parents(HWDB_BIN, 0755); - err = trie_store(trie, HWDB_BIN); + if (asprintf(&hwdb_bin, "%s/etc/udev/hwdb.bin", root) < 0) { + rc = EXIT_FAILURE; + goto out; + } + mkdir_parents(hwdb_bin, 0755); + err = trie_store(trie, hwdb_bin); if (err < 0) { - log_error("Failure writing hardware database '%s': %s", - HWDB_BIN, strerror(-err)); + log_error("Failure writing database %s: %s", hwdb_bin, strerror(-err)); rc = EXIT_FAILURE; } }