summaryrefslogtreecommitdiff
path: root/src/binfmt.c
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2011-04-25 20:41:47 +0200
committerKay Sievers <kay.sievers@vrfy.org>2011-04-25 20:41:47 +0200
commitdb1413d7380acacc4e50faf801ca0d401da89764 (patch)
tree5525908e3b419149c0458348210fedf37eafc703 /src/binfmt.c
parent3a90ae048233021833ae828c1fc6bf0eeab46197 (diff)
sysctl.d, binfmt.d, modules-load.d: switch to stacked config dirs in /lib, /etc, /run
Diffstat (limited to 'src/binfmt.c')
-rw-r--r--src/binfmt.c78
1 files changed, 23 insertions, 55 deletions
diff --git a/src/binfmt.c b/src/binfmt.c
index 6ebd212ee1..619f6e4aa7 100644
--- a/src/binfmt.c
+++ b/src/binfmt.c
@@ -25,8 +25,11 @@
#include <string.h>
#include <stdio.h>
#include <limits.h>
+#include <stdarg.h>
#include "log.h"
+#include "hashmap.h"
+#include "strv.h"
#include "util.h"
static int delete_rule(const char *rule) {
@@ -80,6 +83,7 @@ static int apply_file(const char *path, bool ignore_enoent) {
return -errno;
}
+ log_debug("apply: %s\n", path);
while (!feof(f)) {
char l[LINE_MAX], *p;
int k;
@@ -111,57 +115,6 @@ finish:
return r;
}
-static int scandir_filter(const struct dirent *d) {
- assert(d);
-
- if (ignore_file(d->d_name))
- return 0;
-
- if (d->d_type != DT_REG &&
- d->d_type != DT_LNK &&
- d->d_type != DT_UNKNOWN)
- return 0;
-
- return endswith(d->d_name, ".conf");
-}
-
-static int apply_tree(const char *path) {
- struct dirent **de = NULL;
- int n, i, r = 0;
-
- if ((n = scandir(path, &de, scandir_filter, alphasort)) < 0) {
-
- if (errno == ENOENT)
- return 0;
-
- log_error("Failed to enumerate %s files: %m", path);
- return -errno;
- }
-
- for (i = 0; i < n; i++) {
- char *fn;
- int k;
-
- k = asprintf(&fn, "%s/%s", path, de[i]->d_name);
- free(de[i]);
-
- if (k < 0) {
- log_error("Failed to allocate file name.");
-
- if (r == 0)
- r = -ENOMEM;
- continue;
- }
-
- if ((k = apply_file(fn, true)) < 0 && r == 0)
- r = k;
- }
-
- free(de);
-
- return r;
-}
-
int main(int argc, char *argv[]) {
int r = 0;
@@ -174,14 +127,29 @@ int main(int argc, char *argv[]) {
log_parse_environment();
log_open();
- if (argc > 1)
+ if (argc > 1) {
r = apply_file(argv[1], false);
- else {
+ } else {
+ char **files, **f;
+
/* Flush out all rules */
write_one_line_file("/proc/sys/fs/binfmt_misc/status", "-1");
- r = apply_tree("/etc/binfmt.d");
- }
+ files = conf_files_list(".conf",
+ "/run/binfmt.d",
+ "/etc/binfmt.d",
+ "/usr/lib/binfmt.d",
+ NULL);
+ STRV_FOREACH(f, files) {
+ int k;
+
+ k = apply_file(*f, true);
+ if (k < 0 && r == 0)
+ r = k;
+ }
+
+ strv_free(files);
+ }
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}