From 33488f19793dc0a86fdee27266c5319b5b78d695 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Fri, 17 Oct 2014 15:01:01 +0200 Subject: udev hwdb: Support shipping pre-compiled database in system images In some cases it is preferable to ship system images with a pre-generated binary hwdb database, to avoid having to build it at runtime, avoid shipping the source hwdb files, or avoid storing large binary files in /etc. So if hwdb.bin does not exist in /etc/udev/, fall back to looking for it in UDEVLIBEXECDIR. This keeps the possibility to add files to /etc/udev/hwdb.d/ and re-generating the database which trumps the one in /usr/lib. Add a new --usr flag to "udevadm hwdb --update" which puts the database into UDEVLIBEXECDIR. Adjust systemd-udev-hwdb-update.service to not generate the file in /etc if we already have it in /usr. --- src/udev/udevadm-hwdb.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/udev/udevadm-hwdb.c') diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c index 64273fbe8d..3ca755e2ed 100644 --- a/src/udev/udevadm-hwdb.c +++ b/src/udev/udevadm-hwdb.c @@ -536,14 +536,20 @@ static int import_file(struct udev *udev, struct trie *trie, const char *filenam static void help(void) { printf("Usage: udevadm hwdb OPTIONS\n" " -u,--update update the hardware database\n" + " --usr generate in " UDEVLIBEXECDIR " instead of /etc/udev\n" " -t,--test=MODALIAS query database and print result\n" " -r,--root=PATH alternative root path in the filesystem\n" " -h,--help\n\n"); } static int adm_hwdb(struct udev *udev, int argc, char *argv[]) { + enum { + ARG_USR = 0x100, + }; + static const struct option options[] = { { "update", no_argument, NULL, 'u' }, + { "usr", no_argument, NULL, ARG_USR }, { "test", required_argument, NULL, 't' }, { "root", required_argument, NULL, 'r' }, { "help", no_argument, NULL, 'h' }, @@ -551,6 +557,7 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) { }; const char *test = NULL; const char *root = ""; + const char *hwdb_bin_dir = "/etc/udev"; bool update = false; struct trie *trie = NULL; int err, c; @@ -561,6 +568,9 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) { case 'u': update = true; break; + case ARG_USR: + hwdb_bin_dir = UDEVLIBEXECDIR; + break; case 't': test = optarg; break; @@ -634,7 +644,8 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) { log_debug("strings dedup'ed: %8zu bytes (%8zu)", trie->strings->dedup_len, trie->strings->dedup_count); - if (asprintf(&hwdb_bin, "%s/etc/udev/hwdb.bin", root) < 0) { + hwdb_bin = strjoin(root, "/", hwdb_bin_dir, "/hwdb.bin", NULL); + if (!hwdb_bin) { rc = EXIT_FAILURE; goto out; } -- cgit v1.2.3-54-g00ecf