[systemd-commits] 2 commits - man/udevadm.xml src/shared src/udev

Kay Sievers kay at kemper.freedesktop.org
Fri Feb 8 03:04:57 PST 2013


 man/udevadm.xml         |    6 ++++++
 src/shared/conf-files.c |   29 +++++++++++++----------------
 src/udev/udevadm-hwdb.c |   23 +++++++++++++++++------
 3 files changed, 36 insertions(+), 22 deletions(-)

New commits:
commit 3e49f2ecb55185966ee425a45fcd7b8c2526f3af
Author: Kay Sievers <kay at vrfy.org>
Date:   Fri Feb 8 12:00:05 2013 +0100

    udev: udevadm hwdb - add --root=
    
    https://bugs.freedesktop.org/show_bug.cgi?id=60398

diff --git a/man/udevadm.xml b/man/udevadm.xml
index 7791028..d0b257d 100644
--- a/man/udevadm.xml
+++ b/man/udevadm.xml
@@ -443,6 +443,12 @@
             retrieved properties.</para>
           </listitem>
         </varlistentry>
+        <varlistentry>
+          <term><option>--root=<replaceable>string</replaceable></option></term>
+          <listitem>
+            <para>Alternative root path in the filesystem for reading and writing files.</para>
+          </listitem>
+        </varlistentry>
       </variablelist>
     </refsect2>
 
diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c
index 596a89b..ca1bf16 100644
--- a/src/udev/udevadm-hwdb.c
+++ b/src/udev/udevadm-hwdb.c
@@ -471,18 +471,21 @@ static int import_file(struct trie *trie, const char *filename) {
 static void help(void) {
         printf("Usage: udevadm hwdb OPTIONS\n"
                "  --update            update the hardware database\n"
-               "  --test <modalias>   query database and print result\n"
+               "  --test=<modalias>   query database and print result\n"
+               "  --root=<path>       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", NULL, (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,10 +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("/etc/udev/hwdb.bin", 0755);
-                err = trie_store(trie, "/etc/udev/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 database /etc/udev/hwdb.bin: %s", strerror(-err));
+                        log_error("Failure writing database %s: %s", hwdb_bin, strerror(-err));
                         rc = EXIT_FAILURE;
                 }
         }

commit e02caf30ac6ed2e14f2e6c7f237fde2a3a7acf5d
Author: Kay Sievers <kay at vrfy.org>
Date:   Fri Feb 8 10:45:30 2013 +0100

    shared: conf-files - use root parameter and convert to auto-cleanup

diff --git a/src/shared/conf-files.c b/src/shared/conf-files.c
index 368b7bf..5bbd238 100644
--- a/src/shared/conf-files.c
+++ b/src/shared/conf-files.c
@@ -38,10 +38,13 @@
 #include "conf-files.h"
 
 static int files_add(Hashmap *h, const char *root, const char *path, const char *suffix) {
-        DIR *dir;
-        int r = 0;
+        _cleanup_closedir_ DIR *dir;
+        _cleanup_free_ char *dirpath = NULL;
 
-        dir = opendir(path);
+        if (asprintf(&dirpath, "%s%s", root ? root : "", path) < 0)
+                return -ENOMEM;
+
+        dir = opendir(dirpath);
         if (!dir) {
                 if (errno == ENOENT)
                         return 0;
@@ -51,14 +54,12 @@ static int files_add(Hashmap *h, const char *root, const char *path, const char
         for (;;) {
                 struct dirent *de;
                 union dirent_storage buf;
-                int k;
                 char *p;
+                int err;
 
-                k = readdir_r(dir, &buf.de, &de);
-                if (k != 0) {
-                        r = -k;
-                        goto finish;
-                }
+                err = readdir_r(dir, &buf.de, &de);
+                if (err != 0)
+                        return err;
 
                 if (!de)
                         break;
@@ -66,10 +67,8 @@ static int files_add(Hashmap *h, const char *root, const char *path, const char
                 if (!dirent_is_file_with_suffix(de, suffix))
                         continue;
 
-                if (asprintf(&p, "%s/%s", path, de->d_name) < 0) {
-                        r = -ENOMEM;
-                        goto finish;
-                }
+                if (asprintf(&p, "%s/%s", dirpath, de->d_name) < 0)
+                        return -ENOMEM;
 
                 if (hashmap_put(h, path_get_file_name(p), p) <= 0) {
                         log_debug("Skip overridden file: %s.", p);
@@ -77,9 +76,7 @@ static int files_add(Hashmap *h, const char *root, const char *path, const char
                 }
         }
 
-finish:
-        closedir(dir);
-        return r;
+        return 0;
 }
 
 static int base_cmp(const void *a, const void *b) {



More information about the systemd-commits mailing list