util: conf_files_list() return list as parameter

This commit is contained in:
Kay Sievers 2011-04-28 23:51:24 +02:00
parent b23de6af89
commit 44143309dd
8 changed files with 51 additions and 35 deletions

6
TODO
View File

@ -63,7 +63,7 @@ Features:
* maybe add tiny dbus services similar to hostnamed for locale and wallclock/timezone? * maybe add tiny dbus services similar to hostnamed for locale and wallclock/timezone?
* allow port = 0 in .socket units * allow port=0 in .socket units
* rename systemd-logger to systemd-stdio-syslog-bridge * rename systemd-logger to systemd-stdio-syslog-bridge
@ -123,6 +123,8 @@ Features:
about policy loading. Probably check for available selinux in /proc/filesystems, about policy loading. Probably check for available selinux in /proc/filesystems,
and check for active selinux with getcon_raw() == "kernel" and check for active selinux with getcon_raw() == "kernel"
* move /selinux to /sys/fs/selinux
* Support --test based on current system state * Support --test based on current system state
* systemctl enable as D-Bus call * systemctl enable as D-Bus call
@ -231,7 +233,7 @@ External:
* make cryptsetup lower --iter-time * make cryptsetup lower --iter-time
* patch kernel for xattr support in /dev, /proc/, /sys and /sys/fs/cgroup. * patch kernel for xattr support in /dev, /proc/, /sys and /sys/fs/cgroup?
* patch kernel for cpu feature modalias for autoloading aes/kvm/... * patch kernel for cpu feature modalias for autoloading aes/kvm/...
http://git.kernel.org/?p=linux/kernel/git/ak/linux-misc-2.6.git;a=shortlog;h=refs/heads/cpuid-match http://git.kernel.org/?p=linux/kernel/git/ak/linux-misc-2.6.git;a=shortlog;h=refs/heads/cpuid-match

View File

@ -135,11 +135,16 @@ int main(int argc, char *argv[]) {
/* Flush out all rules */ /* Flush out all rules */
write_one_line_file("/proc/sys/fs/binfmt_misc/status", "-1"); write_one_line_file("/proc/sys/fs/binfmt_misc/status", "-1");
files = conf_files_list(".conf", r = conf_files_list(&files, ".conf",
"/run/binfmt.d", "/run/binfmt.d",
"/etc/binfmt.d", "/etc/binfmt.d",
"/usr/lib/binfmt.d", "/usr/lib/binfmt.d",
NULL); NULL);
if (r < 0) {
log_error("Failed to enumerate binfmt.d files: %s", strerror(-r));
goto finish;
}
STRV_FOREACH(f, files) { STRV_FOREACH(f, files) {
int k; int k;
@ -151,5 +156,6 @@ int main(int argc, char *argv[]) {
strv_free(files); strv_free(files);
} }
finish:
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
} }

View File

@ -1322,7 +1322,7 @@ int bus_fdset_add_all(Manager *m, FDSet *fds) {
* set to pass over to the newly executed systemd. They won't * set to pass over to the newly executed systemd. They won't
* be used there however, except that they are closed at the * be used there however, except that they are closed at the
* very end of deserialization, those making it possible for * very end of deserialization, those making it possible for
* clients to synchronously wait for systemd to reexec buy * clients to synchronously wait for systemd to reexec by
* simply waiting for disconnection */ * simply waiting for disconnection */
SET_FOREACH(c, m->bus_connections_for_dispatch, i) { SET_FOREACH(c, m->bus_connections_for_dispatch, i) {

View File

@ -53,13 +53,12 @@ int main(int argc, char *argv[]) {
n_arguments = n_allocated = 3; n_arguments = n_allocated = 3;
files = conf_files_list(".conf", if (conf_files_list(&files, ".conf",
"/run/modules-load.d", "/run/modules-load.d",
"/etc/modules-load.d", "/etc/modules-load.d",
"/usr/lib/modules-load.d", "/usr/lib/modules-load.d",
NULL); NULL) < 0) {
if (files == NULL) { log_error("Failed to enumerate modules-load.d files: %s", strerror(-r));
log_error("Failed to enumerate modules-load.d files: %m");
goto finish; goto finish;
} }

View File

@ -138,13 +138,17 @@ int main(int argc, char *argv[]) {
else { else {
char **files, **f; char **files, **f;
r = apply_file("/etc/sysctl.conf", true); apply_file("/etc/sysctl.conf", true);
files = conf_files_list(".conf", r = conf_files_list(&files, ".conf",
"/run/sysctl.d", "/run/sysctl.d",
"/etc/sysctl.d", "/etc/sysctl.d",
"/usr/lib/sysctl.d", "/usr/lib/sysctl.d",
NULL); NULL);
if (r < 0) {
log_error("Failed to enumerate sysctl.d files: %s", strerror(-r));
goto finish;
}
STRV_FOREACH(f, files) { STRV_FOREACH(f, files) {
int k; int k;
@ -156,6 +160,6 @@ int main(int argc, char *argv[]) {
strv_free(files); strv_free(files);
} }
finish:
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
} }

View File

@ -963,11 +963,16 @@ int main(int argc, char *argv[]) {
} else { } else {
char **files, **f; char **files, **f;
files = conf_files_list(".conf", r = conf_files_list(&files, ".conf",
"/run/tmpfiles.d", "/run/tmpfiles.d",
"/etc/tmpfiles.d", "/etc/tmpfiles.d",
"/usr/lib/tmpfiles.d", "/usr/lib/tmpfiles.d",
NULL); NULL);
if (r < 0) {
r = EXIT_FAILURE;
log_error("Failed to enumerate tmpfiles.d files: %s", strerror(-r));
goto finish;
}
STRV_FOREACH(f, files) { STRV_FOREACH(f, files) {
if (read_config_file(*f, true) < 0) if (read_config_file(*f, true) < 0)

View File

@ -4606,15 +4606,15 @@ static int base_cmp(const void *a, const void *b) {
return strcmp(file_name_from_path(s1), file_name_from_path(s2)); return strcmp(file_name_from_path(s1), file_name_from_path(s2));
} }
char **conf_files_list(const char *suffix, const char *dir, ...) { int conf_files_list(char ***strv, const char *suffix, const char *dir, ...) {
Hashmap *fh; Hashmap *fh;
char **files = NULL; char **files = NULL;
va_list ap; va_list ap;
int e = 0; int r = 0;
fh = hashmap_new(string_hash_func, string_compare_func); fh = hashmap_new(string_hash_func, string_compare_func);
if (!fh) { if (!fh) {
e = ENOMEM; r = -ENOMEM;
goto finish; goto finish;
} }
@ -4622,7 +4622,7 @@ char **conf_files_list(const char *suffix, const char *dir, ...) {
while (dir) { while (dir) {
if (files_add(fh, dir, suffix) < 0) { if (files_add(fh, dir, suffix) < 0) {
log_error("Failed to search for files."); log_error("Failed to search for files.");
e = EINVAL; r = -EINVAL;
goto finish; goto finish;
} }
dir = va_arg(ap, const char *); dir = va_arg(ap, const char *);
@ -4632,13 +4632,13 @@ char **conf_files_list(const char *suffix, const char *dir, ...) {
files = hashmap_get_strv(fh); files = hashmap_get_strv(fh);
if (files == NULL) { if (files == NULL) {
log_error("Failed to compose list of files."); log_error("Failed to compose list of files.");
e = ENOMEM; r = -ENOMEM;
goto finish; goto finish;
} }
qsort(files, hashmap_size(fh), sizeof(char *), base_cmp); qsort(files, hashmap_size(fh), sizeof(char *), base_cmp);
finish: finish:
hashmap_free(fh); hashmap_free(fh);
errno = e; *strv = files;
return files; return r;
} }

View File

@ -442,5 +442,5 @@ int signal_from_string(const char *s);
int signal_from_string_try_harder(const char *s); int signal_from_string_try_harder(const char *s);
char **conf_files_list(const char *suffix, const char *dir, ...); int conf_files_list(char ***strv, const char *suffix, const char *dir, ...);
#endif #endif