summaryrefslogtreecommitdiff
path: root/load-fragment.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-01-18 23:50:13 +0100
committerLennart Poettering <lennart@poettering.net>2010-01-18 23:50:13 +0100
commit87d1515de5ae611e95144def9ef4b2c0c933f6fe (patch)
tree4cdeceee70826dffd460775aaddbea8e60e51eaa /load-fragment.c
parent91cdde8a7a08c6797995cc67f4b55ac43780cdd8 (diff)
first try at implementing dependency loader
Diffstat (limited to 'load-fragment.c')
-rw-r--r--load-fragment.c105
1 files changed, 82 insertions, 23 deletions
diff --git a/load-fragment.c b/load-fragment.c
index b5b3e4862f..4510cc9163 100644
--- a/load-fragment.c
+++ b/load-fragment.c
@@ -9,7 +9,7 @@
#include "conf-parser.h"
#include "load-fragment.h"
-int config_parse_names(
+int config_parse_deps(
const char *filename,
unsigned line,
const char *section,
@@ -54,41 +54,100 @@ int config_parse_names(
return 0;
}
+int config_parse_names(
+ const char *filename,
+ unsigned line,
+ const char *section,
+ const char *lvalue,
+ const char *rvalue,
+ void *data,
+ void *userdata) {
+
+ Set **set = data;
+ Name *name = userdata;
+ char *w;
+ size_t l;
+ char *state;
+
+ assert(filename);
+ assert(lvalue);
+ assert(rvalue);
+ assert(data);
+
+ FOREACH_WORD(w, &l, rvalue, state) {
+ char *t;
+ int r;
+ Name *other;
+
+ if (!(t = strndup(w, l)))
+ return -ENOMEM;
+
+ other = manager_get_name(name->meta.manager, t);
+
+ if (other) {
+
+ if (other != name) {
+
+ if (other->meta.state != NAME_STUB) {
+ free(t);
+ return -EEXIST;
+ }
+
+ if ((r = name_merge(name, other) < 0)) {
+ free(t);
+ return r;
+ }
+ }
+
+ } else {
+
+ if (!*set)
+ if (!(*set = set_new(trivial_hash_func, trivial_compare_func))) {
+ free(t);
+ return -ENOMEM;
+ }
+
+ if ((r = set_put(*set, t)) < 0) {
+ free(t);
+ return r;
+ }
+ }
+
+ free(t);
+ }
+
+ return 0;
+}
+
int name_load_fragment(Name *n) {
const ConfigItem items[] = {
- { "Names", config_parse_strv, &n->meta.names, "Meta" },
- { "Description", config_parse_string, &n->meta.description, "Meta" },
- { "Requires", config_parse_names, &n->meta.requires, "Meta" },
- { "SoftRequires", config_parse_names, &n->meta.soft_requires, "Meta" },
- { "Wants", config_parse_names, &n->meta.wants, "Meta" },
- { "Requisite", config_parse_names, &n->meta.requisite, "Meta" },
- { "SoftRequisite", config_parse_names, &n->meta.soft_requisite, "Meta" },
- { "Conflicts", config_parse_names, &n->meta.conflicts, "Meta" },
- { "Before", config_parse_names, &n->meta.before, "Meta" },
- { "After", config_parse_names, &n->meta.after, "Meta" },
+ { "Names", config_parse_names, &n->meta.names, "Meta" },
+ { "Description", config_parse_string, &n->meta.description, "Meta" },
+ { "Requires", config_parse_deps, n->meta.dependencies+NAME_REQUIRES, "Meta" },
+ { "SoftRequires", config_parse_deps, n->meta.dependencies+NAME_SOFT_REQUIRES, "Meta" },
+ { "Wants", config_parse_deps, n->meta.dependencies+NAME_WANTS, "Meta" },
+ { "Requisite", config_parse_deps, n->meta.dependencies+NAME_REQUISITE, "Meta" },
+ { "SoftRequisite", config_parse_deps, n->meta.dependencies+NAME_SOFT_REQUISITE, "Meta" },
+ { "Conflicts", config_parse_deps, n->meta.dependencies+NAME_CONFLICTS, "Meta" },
+ { "Before", config_parse_deps, n->meta.dependencies+NAME_BEFORE, "Meta" },
+ { "After", config_parse_deps, n->meta.dependencies+NAME_AFTER, "Meta" },
{ NULL, NULL, NULL, NULL }
};
- char **t, **l;
+ char *t;
int r;
+ void *state;
assert(n);
assert(n->meta.state == NAME_STUB);
- /* We copy the strv here so that we can iterate through it
- * while being safe for modification */
- if (!(l = strv_copy(n->meta.names)))
- return -ENOMEM;
-
- STRV_FOREACH(t, n->meta.names)
- if ((r = config_parse(*t, items, n)) < 0)
+ SET_FOREACH(t, n->meta.names, state)
+ if ((r = config_parse(t, items, n)) < 0)
goto fail;
- return 0;
+ r = 0;
fail:
-
- strv_free(l);
- return 0;
+ return r;
}