[systemd-commits] 5 commits - Makefile.am src/binfmt src/modules-load src/shared src/sysctl src/tmpfiles src/udev
Kay Sievers
kay at kemper.freedesktop.org
Mon May 7 11:54:20 PDT 2012
Makefile.am | 6 -
src/binfmt/binfmt.c | 1
src/modules-load/modules-load.c | 1
src/shared/conf-files.c | 151 ++++++++++++++++++++++++++++++++++++++++
src/shared/conf-files.h | 31 ++++++++
src/shared/install.c | 1
src/shared/util.c | 113 -----------------------------
src/shared/util.h | 2
src/sysctl/sysctl.c | 1
src/tmpfiles/tmpfiles.c | 1
src/udev/udev-builtin-path_id.c | 14 +++
src/udev/udev-rules.c | 138 +++++++++++++-----------------------
src/udev/udev.h | 1
13 files changed, 254 insertions(+), 207 deletions(-)
New commits:
commit 2c21044f05e32ec483b6ab13e175278779e9ebe3
Author: Kay Sievers <kay at vrfy.org>
Date: Mon May 7 18:55:45 2012 +0200
util: split-out conf-file.[ch]
diff --git a/Makefile.am b/Makefile.am
index c85a401..2bc8e01 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -547,6 +547,8 @@ libsystemd_shared_la_SOURCES = \
src/shared/ioprio.h \
src/shared/socket-util.c \
src/shared/socket-util.h \
+ src/shared/conf-files.c \
+ src/shared/conf-files.h \
src/shared/cgroup-util.c \
src/shared/cgroup-util.h \
src/shared/cgroup-show.c \
@@ -564,10 +566,6 @@ libsystemd_shared_la_SOURCES = \
src/shared/spawn-polkit-agent.c \
src/shared/spawn-polkit-agent.h
-libsystemd_shared_la_CFLAGS = \
- $(AM_CFLAGS) \
- $(DBUS_CFLAGS)
-
#-------------------------------------------------------------------------------
noinst_LTLIBRARIES += \
libsystemd-dbus.la
diff --git a/src/binfmt/binfmt.c b/src/binfmt/binfmt.c
index 5bd7633..0399ab7 100644
--- a/src/binfmt/binfmt.c
+++ b/src/binfmt/binfmt.c
@@ -31,6 +31,7 @@
#include "hashmap.h"
#include "strv.h"
#include "util.h"
+#include "conf-files.h"
static int delete_rule(const char *rule) {
char *x, *fn = NULL, *e;
diff --git a/src/modules-load/modules-load.c b/src/modules-load/modules-load.c
index 0f2144c..c78f7d8 100644
--- a/src/modules-load/modules-load.c
+++ b/src/modules-load/modules-load.c
@@ -31,6 +31,7 @@
#include "log.h"
#include "util.h"
#include "strv.h"
+#include "conf-files.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
diff --git a/src/shared/conf-files.c b/src/shared/conf-files.c
new file mode 100644
index 0000000..019fadc
--- /dev/null
+++ b/src/shared/conf-files.c
@@ -0,0 +1,151 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2010 Lennart Poettering
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <assert.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <dirent.h>
+
+#include "macro.h"
+#include "util.h"
+#include "missing.h"
+#include "log.h"
+#include "strv.h"
+#include "hashmap.h"
+#include "conf-files.h"
+
+static int files_add(Hashmap *h, const char *path, const char *suffix) {
+ DIR *dir;
+ struct dirent buffer, *de;
+ int r = 0;
+
+ dir = opendir(path);
+ if (!dir) {
+ if (errno == ENOENT)
+ return 0;
+ return -errno;
+ }
+
+ for (;;) {
+ int k;
+ char *p;
+
+ k = readdir_r(dir, &buffer, &de);
+ if (k != 0) {
+ r = -k;
+ goto finish;
+ }
+
+ if (!de)
+ break;
+
+ if (!dirent_is_file_with_suffix(de, suffix))
+ continue;
+
+ if (asprintf(&p, "%s/%s", path, de->d_name) < 0) {
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ if (hashmap_put(h, file_name_from_path(p), p) <= 0) {
+ log_debug("Skip overridden file: %s.", p);
+ free(p);
+ }
+ }
+
+finish:
+ closedir(dir);
+ return r;
+}
+
+static int base_cmp(const void *a, const void *b) {
+ const char *s1, *s2;
+
+ s1 = *(char * const *)a;
+ s2 = *(char * const *)b;
+ return strcmp(file_name_from_path(s1), file_name_from_path(s2));
+}
+
+int conf_files_list_strv(char ***strv, const char *suffix, const char **dirs) {
+ Hashmap *fh = NULL;
+ char **files = NULL;
+ const char **p;
+ int r = 0;
+
+ assert(dirs);
+
+ fh = hashmap_new(string_hash_func, string_compare_func);
+ if (!fh) {
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ STRV_FOREACH(p, dirs) {
+ if (files_add(fh, *p, suffix) < 0) {
+ log_error("Failed to search for files.");
+ r = -EINVAL;
+ goto finish;
+ }
+ }
+
+ files = hashmap_get_strv(fh);
+ if (files == NULL) {
+ log_error("Failed to compose list of files.");
+ r = -ENOMEM;
+ goto finish;
+ }
+ qsort(files, hashmap_size(fh), sizeof(char *), base_cmp);
+
+finish:
+ hashmap_free(fh);
+ *strv = files;
+ return r;
+}
+
+int conf_files_list(char ***strv, const char *suffix, const char *dir, ...) {
+ char **dirs = NULL;
+ va_list ap;
+ int r;
+
+ 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;
+ }
+ strv_uniq(dirs);
+
+ r = conf_files_list_strv(strv, suffix, (const char **)dirs);
+
+finish:
+ strv_free(dirs);
+ return r;
+}
diff --git a/src/shared/conf-files.h b/src/shared/conf-files.h
new file mode 100644
index 0000000..f37ee1f
--- /dev/null
+++ b/src/shared/conf-files.h
@@ -0,0 +1,31 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#ifndef fooconffileshfoo
+#define fooconffileshfoo
+
+/***
+ This file is part of systemd.
+
+ Copyright 2010-2012 Lennart Poettering
+ Copyright 2010-2012 Kay Sievers
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include "macro.h"
+
+int conf_files_list(char ***strv, const char *suffix, const char *dir, ...);
+int conf_files_list_strv(char ***strv, const char *suffix, const char **dirs);
+
+#endif
diff --git a/src/shared/install.c b/src/shared/install.c
index a982c54..a77dfc7 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -34,6 +34,7 @@
#include "unit-name.h"
#include "install.h"
#include "conf-parser.h"
+#include "conf-files.h"
typedef struct {
char *name;
diff --git a/src/shared/util.c b/src/shared/util.c
index 2bfa2cb..d6f5661 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -4863,120 +4863,6 @@ int vt_disallocate(const char *name) {
return 0;
}
-static int files_add(Hashmap *h, const char *path, const char *suffix) {
- DIR *dir;
- struct dirent buffer, *de;
- int r = 0;
-
- dir = opendir(path);
- if (!dir) {
- if (errno == ENOENT)
- return 0;
- return -errno;
- }
-
- for (;;) {
- int k;
- char *p;
-
- k = readdir_r(dir, &buffer, &de);
- if (k != 0) {
- r = -k;
- goto finish;
- }
-
- if (!de)
- break;
-
- if (!dirent_is_file_with_suffix(de, suffix))
- continue;
-
- if (asprintf(&p, "%s/%s", path, de->d_name) < 0) {
- r = -ENOMEM;
- goto finish;
- }
-
- if (hashmap_put(h, file_name_from_path(p), p) <= 0) {
- log_debug("Skip overridden file: %s.", p);
- free(p);
- }
- }
-
-finish:
- closedir(dir);
- return r;
-}
-
-static int base_cmp(const void *a, const void *b) {
- const char *s1, *s2;
-
- s1 = *(char * const *)a;
- s2 = *(char * const *)b;
- return strcmp(file_name_from_path(s1), file_name_from_path(s2));
-}
-
-int conf_files_list_strv(char ***strv, const char *suffix, const char **dirs) {
- Hashmap *fh = NULL;
- char **files = NULL;
- const char **p;
- int r = 0;
-
- assert(dirs);
-
- fh = hashmap_new(string_hash_func, string_compare_func);
- if (!fh) {
- r = -ENOMEM;
- goto finish;
- }
-
- STRV_FOREACH(p, dirs) {
- if (files_add(fh, *p, suffix) < 0) {
- log_error("Failed to search for files.");
- r = -EINVAL;
- goto finish;
- }
- }
-
- files = hashmap_get_strv(fh);
- if (files == NULL) {
- log_error("Failed to compose list of files.");
- r = -ENOMEM;
- goto finish;
- }
- qsort(files, hashmap_size(fh), sizeof(char *), base_cmp);
-
-finish:
- hashmap_free(fh);
- *strv = files;
- return r;
-}
-
-int conf_files_list(char ***strv, const char *suffix, const char *dir, ...) {
- char **dirs = NULL;
- va_list ap;
- int r;
-
- 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;
- }
- strv_uniq(dirs);
-
- r = conf_files_list_strv(strv, suffix, (const char **)dirs);
-
-finish:
- strv_free(dirs);
- return r;
-}
-
int hwclock_is_localtime(void) {
FILE *f;
bool local = false;
diff --git a/src/shared/util.h b/src/shared/util.h
index 7a2661a..b246996 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -460,9 +460,6 @@ int symlink_or_copy_atomic(const char *from, const char *to);
int fchmod_umask(int fd, mode_t mode);
-int conf_files_list(char ***strv, const char *suffix, const char *dir, ...);
-int conf_files_list_strv(char ***strv, const char *suffix, const char **dirs);
-
int hwclock_is_localtime(void);
int hwclock_apply_localtime_delta(int *min);
int hwclock_reset_localtime_delta(void);
diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c
index 57fba25..575095f 100644
--- a/src/sysctl/sysctl.c
+++ b/src/sysctl/sysctl.c
@@ -31,6 +31,7 @@
#include "strv.h"
#include "util.h"
#include "strv.h"
+#include "conf-files.h"
#define PROC_SYS_PREFIX "/proc/sys/"
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index d8fcb40..16666ce 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -45,6 +45,7 @@
#include "strv.h"
#include "label.h"
#include "set.h"
+#include "conf-files.h"
/* This reads all files listed in /etc/tmpfiles.d/?*.conf and creates
* them in the file system. This is intended to be used to create
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index 22b91c6..45a6114 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -31,6 +31,7 @@
#include <time.h>
#include "udev.h"
+#include "conf-files.h"
#define PREALLOC_TOKEN 2048
#define PREALLOC_STRBUF 32 * 1024
commit 7fdd367e6d675d4546074c5dd35bf168d7c17339
Author: Kay Sievers <kay at vrfy.org>
Date: Mon May 7 18:47:58 2012 +0200
udev: path_id - skip PCI-only-parents for block devices
diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c
index 09abefc..0a1cd3b 100644
--- a/src/udev/udev-builtin-path_id.c
+++ b/src/udev/udev-builtin-path_id.c
@@ -407,6 +407,7 @@ static int builtin_path_id(struct udev_device *dev, int argc, char *argv[], bool
{
struct udev_device *parent;
char *path = NULL;
+ bool some_transport = false;
/* S390 ccw bus */
parent = udev_device_get_parent_with_subsystem_devtype(dev, "ccw", NULL);
@@ -427,8 +428,10 @@ static int builtin_path_id(struct udev_device *dev, int argc, char *argv[], bool
handle_scsi_tape(parent, &path);
} else if (strcmp(subsys, "scsi") == 0) {
parent = handle_scsi(parent, &path);
+ some_transport = true;
} else if (strcmp(subsys, "usb") == 0) {
parent = handle_usb(parent, &path);
+ some_transport = true;
} else if (strcmp(subsys, "serio") == 0) {
path_prepend(&path, "serio-%s", udev_device_get_sysnum(parent));
parent = skip_subsystem(parent, "serio");
@@ -451,6 +454,17 @@ static int builtin_path_id(struct udev_device *dev, int argc, char *argv[], bool
parent = udev_device_get_parent(parent);
}
+
+ /*
+ * Do not return a single-parent-device-only for block
+ * devices, they might have entire buses behind it which
+ * do not get unique IDs only by using the parent device.
+ */
+ if (!some_transport && streq(udev_device_get_subsystem(dev), "block")) {
+ free(path);
+ path = NULL;
+ }
+
out:
if (path != NULL) {
char tag[UTIL_NAME_SIZE];
commit 775f8b3c74e796e1215aa06b8ea4c5d354bc50ee
Author: Kay Sievers <kay at vrfy.org>
Date: Mon May 7 13:21:05 2012 +0200
udev: use conf_files_list() to search rules files
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index e73b156..22b91c6 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -36,13 +36,6 @@
#define PREALLOC_STRBUF 32 * 1024
#define PREALLOC_TRIE 256
-/* configuration directories with last modification timestamp */
-static const char *rules_dirs[] = {
- TEST_PREFIX UDEVLIBEXECDIR "/rules.d",
- TEST_PREFIX "/run/udev/rules.d",
- TEST_PREFIX SYSCONFDIR "/udev/rules.d",
-};
-
struct uid_gid {
unsigned int name_off;
union {
@@ -65,7 +58,8 @@ struct trie_node {
struct udev_rules {
struct udev *udev;
- unsigned long long dirs_ts_usec[ELEMENTSOF(rules_dirs)];
+ char **dirs;
+ unsigned long long *dirs_ts_usec;
int resolve_names;
/* every key in the rules file becomes a token */
@@ -79,7 +73,7 @@ struct udev_rules {
size_t buf_max;
unsigned int buf_count;
- /* during rule parsing, strings are indexed to find duplicates */
+ /* during rule parsing, strings are indexed and de-duplicated */
struct trie_node *trie_nodes;
unsigned int trie_nodes_cur;
unsigned int trie_nodes_max;
@@ -1188,7 +1182,9 @@ static int add_rule(struct udev_rules *rules, char *line,
memset(&rule_tmp, 0x00, sizeof(struct rule_tmp));
rule_tmp.rules = rules;
rule_tmp.rule.type = TK_RULE;
- rule_tmp.rule.rule.filename_off = filename_off;
+ /* the offset in the rule is limited to unsigned short */
+ if (filename_off < USHRT_MAX)
+ rule_tmp.rule.rule.filename_off = filename_off;
rule_tmp.rule.rule.filename_line = lineno;
linepos = line;
@@ -1632,21 +1628,27 @@ invalid:
return -1;
}
-static int parse_file(struct udev_rules *rules, const char *filename, unsigned short filename_off)
+static int parse_file(struct udev_rules *rules, const char *filename)
{
FILE *f;
unsigned int first_token;
+ unsigned int filename_off;
char line[UTIL_LINE_SIZE];
int line_nr = 0;
unsigned int i;
- log_debug("reading '%s' as rules file\n", filename);
+ if (null_or_empty_path(filename)) {
+ log_debug("skip empty file: %s\n", filename);
+ return 0;
+ }
+ log_debug("read rules file: %s\n", filename);
f = fopen(filename, "r");
if (f == NULL)
return -1;
first_token = rules->token_cur;
+ filename_off = add_string(rules, filename);
while (fgets(line, sizeof(line), f) != NULL) {
char *key;
@@ -1707,52 +1709,13 @@ static int parse_file(struct udev_rules *rules, const char *filename, unsigned s
return 0;
}
-static int add_matching_files(struct udev *udev, struct udev_list *file_list, const char *dirname, const char *suffix)
-{
- DIR *dir;
- struct dirent *dent;
- char filename[UTIL_PATH_SIZE];
-
- dir = opendir(dirname);
- if (dir == NULL) {
- log_debug("unable to open '%s': %m\n", dirname);
- return -1;
- }
-
- for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
- if (dent->d_name[0] == '.')
- continue;
-
- /* look for file matching with specified suffix */
- if (suffix != NULL) {
- const char *ext;
-
- ext = strrchr(dent->d_name, '.');
- if (ext == NULL)
- continue;
- if (!streq(ext, suffix))
- continue;
- }
- util_strscpyl(filename, sizeof(filename), dirname, "/", dent->d_name, NULL);
- /*
- * the basename is the key, the filename the value
- * identical basenames from different directories override each other
- * entries are sorted after basename
- */
- udev_list_entry_add(file_list, dent->d_name, filename);
- }
-
- closedir(dir);
- return 0;
-}
-
struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names)
{
struct udev_rules *rules;
struct udev_list file_list;
- struct udev_list_entry *file_loop;
struct token end_token;
- unsigned int i;
+ char **files, **f;
+ int r;
rules = calloc(1, sizeof(struct udev_rules));
if (rules == NULL)
@@ -1792,41 +1755,37 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names)
memset(rules->trie_nodes, 0x00, sizeof(struct trie_node));
rules->trie_nodes_cur = 1;
- for (i = 0; i < ELEMENTSOF(rules_dirs); i++)
- add_matching_files(udev, &file_list, rules_dirs[i], ".rules");
-
- /* add all filenames to the string buffer */
- udev_list_entry_foreach(file_loop, udev_list_get_entry(&file_list)) {
- const char *filename = udev_list_entry_get_value(file_loop);
- unsigned int filename_off;
-
- filename_off = add_string(rules, filename);
- /* the offset in the rule is limited to unsigned short */
- if (filename_off < USHRT_MAX)
- udev_list_entry_set_num(file_loop, filename_off);
+ rules->dirs = strv_new(TEST_PREFIX SYSCONFDIR "/udev/rules.d",
+ TEST_PREFIX "/run/udev/rules.d",
+ TEST_PREFIX UDEVLIBEXECDIR "/rules.d",
+ NULL);
+ if (!rules->dirs) {
+ log_error("failed to build config directory array");
+ return NULL;
+ }
+ if (!strv_path_canonicalize(rules->dirs)) {
+ log_error("failed to canonicalize config directories\n");
+ return NULL;
+ }
+ strv_uniq(rules->dirs);
+ r = conf_files_list_strv(&files, ".rules", (const char **)rules->dirs);
+ if (r < 0) {
+ log_error("failed to enumerate rules files: %s\n", strerror(-r));
+ return NULL;
}
+ rules->dirs_ts_usec = calloc(strv_length(rules->dirs), sizeof(long long));
- /* parse all rules files */
- udev_list_entry_foreach(file_loop, udev_list_get_entry(&file_list)) {
- const char *filename = udev_list_entry_get_value(file_loop);
- unsigned int filename_off = udev_list_entry_get_num(file_loop);
- struct stat st;
+ /*
+ * The offset value in the rules strct is limited; add all
+ * rules file names to the beginning of the string buffer.
+ */
+ STRV_FOREACH(f, files)
+ add_string(rules, *f);
- if (stat(filename, &st) != 0) {
- log_error("can not find '%s': %m\n", filename);
- continue;
- }
- if (S_ISREG(st.st_mode) && st.st_size <= 0) {
- log_debug("ignore empty '%s'\n", filename);
- continue;
- }
- if (S_ISCHR(st.st_mode)) {
- log_debug("ignore masked '%s'\n", filename);
- continue;
- }
- parse_file(rules, filename, filename_off);
- }
- udev_list_cleanup(&file_list);
+ STRV_FOREACH(f, files)
+ parse_file(rules, *f);
+
+ strv_free(files);
memset(&end_token, 0x00, sizeof(struct token));
end_token.type = TK_END;
@@ -1886,6 +1845,8 @@ struct udev_rules *udev_rules_unref(struct udev_rules *rules)
free(rules->trie_nodes);
free(rules->uids);
free(rules->gids);
+ strv_free(rules->dirs);
+ free(rules->dirs_ts_usec);
free(rules);
return NULL;
}
@@ -1895,10 +1856,10 @@ bool udev_rules_check_timestamp(struct udev_rules *rules)
unsigned int i;
bool changed = false;
- for (i = 0; i < ELEMENTSOF(rules_dirs); i++) {
+ for (i = 0; rules->dirs[i]; i++) {
struct stat stats;
- if (stat(rules_dirs[i], &stats) < 0)
+ if (stat(rules->dirs[i], &stats) < 0)
continue;
if (rules->dirs_ts_usec[i] == ts_usec(&stats.st_mtim))
@@ -1906,7 +1867,7 @@ bool udev_rules_check_timestamp(struct udev_rules *rules)
/* first check */
if (rules->dirs_ts_usec[i] != 0) {
- log_debug("reload - timestamp of '%s' changed\n", rules_dirs[i]);
+ log_debug("reload - timestamp of '%s' changed\n", rules->dirs[i]);
changed = true;
}
diff --git a/src/udev/udev.h b/src/udev/udev.h
index aaaf632..56eff00 100644
--- a/src/udev/udev.h
+++ b/src/udev/udev.h
@@ -27,6 +27,7 @@
#include "libudev-private.h"
#include "util.h"
#include "label.h"
+#include "strv.h"
struct udev_event {
struct udev *udev;
commit 0a1a17aa2d9112470124ef5afb9314343777dc29
Author: Kay Sievers <kay at vrfy.org>
Date: Mon May 7 13:20:29 2012 +0200
conf_files_list(): split out conf_files_list_strv()
diff --git a/src/shared/util.c b/src/shared/util.c
index d86df17..2bfa2cb 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -4915,29 +4915,13 @@ static int base_cmp(const void *a, const void *b) {
return strcmp(file_name_from_path(s1), file_name_from_path(s2));
}
-int conf_files_list(char ***strv, const char *suffix, const char *dir, ...) {
+int conf_files_list_strv(char ***strv, const char *suffix, const char **dirs) {
Hashmap *fh = NULL;
- char **dirs = NULL;
char **files = NULL;
- char **p;
- va_list ap;
+ const char **p;
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;
- }
+ assert(dirs);
fh = hashmap_new(string_hash_func, string_compare_func);
if (!fh) {
@@ -4959,16 +4943,40 @@ int conf_files_list(char ***strv, const char *suffix, const char *dir, ...) {
r = -ENOMEM;
goto finish;
}
-
qsort(files, hashmap_size(fh), sizeof(char *), base_cmp);
finish:
- strv_free(dirs);
hashmap_free(fh);
*strv = files;
return r;
}
+int conf_files_list(char ***strv, const char *suffix, const char *dir, ...) {
+ char **dirs = NULL;
+ va_list ap;
+ int r;
+
+ 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;
+ }
+ strv_uniq(dirs);
+
+ r = conf_files_list_strv(strv, suffix, (const char **)dirs);
+
+finish:
+ strv_free(dirs);
+ return r;
+}
+
int hwclock_is_localtime(void) {
FILE *f;
bool local = false;
diff --git a/src/shared/util.h b/src/shared/util.h
index 0246dfd..7a2661a 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -461,6 +461,7 @@ int symlink_or_copy_atomic(const char *from, const char *to);
int fchmod_umask(int fd, mode_t mode);
int conf_files_list(char ***strv, const char *suffix, const char *dir, ...);
+int conf_files_list_strv(char ***strv, const char *suffix, const char **dirs);
int hwclock_is_localtime(void);
int hwclock_apply_localtime_delta(int *min);
commit cd9556cc84523e2d515a8be2648e2a50fb6b2144
Author: Kay Sievers <kay at vrfy.org>
Date: Mon May 7 13:15:25 2012 +0200
conf_files_list(): files-add() - do not canonicalize file names
File names in /etc, /run, /usr/lib are sorted/overridden by basename.
Sorting things like "/dev/null" with the basename "null" in the hash
of config files breaks the ordering and the overriding logic.
diff --git a/src/shared/util.c b/src/shared/util.c
index fd2c5b0..d86df17 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -4877,7 +4877,7 @@ static int files_add(Hashmap *h, const char *path, const char *suffix) {
for (;;) {
int k;
- char *p, *f;
+ char *p;
k = readdir_r(dir, &buffer, &de);
if (k != 0) {
@@ -4896,17 +4896,10 @@ static int files_add(Hashmap *h, const char *path, const char *suffix) {
goto finish;
}
- f = canonicalize_file_name(p);
- if (!f) {
- log_error("Failed to canonicalize file name '%s': %m", p);
+ if (hashmap_put(h, file_name_from_path(p), p) <= 0) {
+ log_debug("Skip overridden file: %s.", p);
free(p);
- continue;
}
- free(p);
-
- log_debug("found: %s\n", f);
- if (hashmap_put(h, file_name_from_path(f), f) <= 0)
- free(f);
}
finish:
More information about the systemd-commits
mailing list