[systemd-commits] src/binfmt.c src/modules-load.c src/sysctl.c src/tmpfiles.c src/util.c

Kay Sievers kay at kemper.freedesktop.org
Sat Apr 30 11:33:33 PDT 2011


 src/binfmt.c       |    1 +
 src/modules-load.c |    2 ++
 src/sysctl.c       |    2 ++
 src/tmpfiles.c     |    1 +
 src/util.c         |   40 ++++++++++++++++++++++++++++++++--------
 5 files changed, 38 insertions(+), 8 deletions(-)

New commits:
commit 223a35581604897185c46dfc184b0fa32916d59b
Author: Kay Sievers <kay.sievers at vrfy.org>
Date:   Sat Apr 30 20:31:33 2011 +0200

    binfmt, modules-load, sysctl, tmpfiles: read /usr/local/lib and where appropriate /lib directories

diff --git a/src/binfmt.c b/src/binfmt.c
index be1f1ff..a815a11 100644
--- a/src/binfmt.c
+++ b/src/binfmt.c
@@ -138,6 +138,7 @@ int main(int argc, char *argv[]) {
                 r = conf_files_list(&files, ".conf",
                                     "/run/binfmt.d",
                                     "/etc/binfmt.d",
+                                    "/usr/local/lib/binfmt.d",
                                     "/usr/lib/binfmt.d",
                                     NULL);
 
diff --git a/src/modules-load.c b/src/modules-load.c
index 7efd81f..d76defa 100644
--- a/src/modules-load.c
+++ b/src/modules-load.c
@@ -56,7 +56,9 @@ int main(int argc, char *argv[]) {
         if (conf_files_list(&files, ".conf",
                             "/run/modules-load.d",
                             "/etc/modules-load.d",
+                            "/usr/local/lib/modules-load.d",
                             "/usr/lib/modules-load.d",
+                            "/lib/modules-load.d",
                             NULL) < 0) {
                 log_error("Failed to enumerate modules-load.d files: %s", strerror(-r));
                 goto finish;
diff --git a/src/sysctl.c b/src/sysctl.c
index 814cfea..efa2f53 100644
--- a/src/sysctl.c
+++ b/src/sysctl.c
@@ -143,7 +143,9 @@ int main(int argc, char *argv[]) {
                 r = conf_files_list(&files, ".conf",
                                     "/run/sysctl.d",
                                     "/etc/sysctl.d",
+                                    "/usr/local/sysctl.d",
                                     "/usr/lib/sysctl.d",
+                                    "/lib/sysctl.d",
                                     NULL);
                 if (r < 0) {
                         log_error("Failed to enumerate sysctl.d files: %s", strerror(-r));
diff --git a/src/tmpfiles.c b/src/tmpfiles.c
index f36a75f..954c3b7 100644
--- a/src/tmpfiles.c
+++ b/src/tmpfiles.c
@@ -966,6 +966,7 @@ int main(int argc, char *argv[]) {
                 r = conf_files_list(&files, ".conf",
                                     "/run/tmpfiles.d",
                                     "/etc/tmpfiles.d",
+                                    "/usr/local/lib/tmpfiles.d",
                                     "/usr/lib/tmpfiles.d",
                                     NULL);
                 if (r < 0) {
diff --git a/src/util.c b/src/util.c
index 9b43c21..f0051ee 100644
--- a/src/util.c
+++ b/src/util.c
@@ -4576,17 +4576,25 @@ static int files_add(Hashmap *h, const char *path, const char *suffix) {
         }
 
         for (de = readdir(dir); de; de = readdir(dir)) {
-                char *f;
+                char *p, *f;
                 const char *base;
 
                 if (!file_is_conf(de, suffix))
                         continue;
 
-                if (asprintf(&f, "%s/%s", path, de->d_name) < 0) {
+                if (asprintf(&p, "%s/%s", path, de->d_name) < 0) {
                         r = -ENOMEM;
                         goto finish;
                 }
 
+                f = canonicalize_file_name(p);
+                if (!f) {
+                        log_error("Failed to canonicalize file name '%s': %m", p);
+                        free(p);
+                        continue;
+                }
+                free(p);
+
                 log_debug("found: %s\n", f);
                 base = f + strlen(path) + 1;
                 if (hashmap_put(h, base, f) <= 0)
@@ -4607,27 +4615,42 @@ static int base_cmp(const void *a, const void *b) {
 }
 
 int conf_files_list(char ***strv, const char *suffix, const char *dir, ...) {
-        Hashmap *fh;
+        Hashmap *fh = NULL;
+        char **dirs = NULL;
         char **files = NULL;
+        char **p;
         va_list ap;
         int r = 0;
 
+        va_start(ap, dir);
+        dirs = strv_new_ap(dir, ap);
+        va_end(ap);
+        if (!dirs) {
+                r = -ENOMEM;
+                goto finish;
+        }
+        if (!strv_path_canonicalize(dirs)) {
+                r = -ENOMEM;
+                goto finish;
+        }
+        if (!strv_uniq(dirs)) {
+                r = -ENOMEM;
+                goto finish;
+        }
+
         fh = hashmap_new(string_hash_func, string_compare_func);
         if (!fh) {
                 r = -ENOMEM;
                 goto finish;
         }
 
-        va_start(ap, dir);
-        while (dir) {
-                if (files_add(fh, dir, suffix) < 0) {
+        STRV_FOREACH(p, dirs) {
+                if (files_add(fh, *p, suffix) < 0) {
                         log_error("Failed to search for files.");
                         r = -EINVAL;
                         goto finish;
                 }
-                dir = va_arg(ap, const char *);
         }
-        va_end(ap);
 
         files = hashmap_get_strv(fh);
         if (files == NULL) {
@@ -4638,6 +4661,7 @@ int conf_files_list(char ***strv, const char *suffix, const char *dir, ...) {
 
         qsort(files, hashmap_size(fh), sizeof(char *), base_cmp);
 finish:
+        strv_free(dirs);
         hashmap_free(fh);
         *strv = files;
         return r;



More information about the systemd-commits mailing list