From: Lennart Poettering Date: Thu, 19 Nov 2009 22:13:20 +0000 (+0100) Subject: load-fragment: add missing .c/h files X-Git-Tag: v1~851 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=3efd4195676c3880771b9f5e3b3bd9ff35c5ad4b load-fragment: add missing .c/h files --- diff --git a/load-fragment.c b/load-fragment.c new file mode 100644 index 000000000..b5b3e4862 --- /dev/null +++ b/load-fragment.c @@ -0,0 +1,94 @@ +/*-*- Mode: C; c-basic-offset: 8 -*-*/ + +#include +#include +#include + +#include "name.h" +#include "strv.h" +#include "conf-parser.h" +#include "load-fragment.h" + +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; + + r = manager_load_name(name->meta.manager, t, &other); + free(t); + + if (r < 0) + return r; + + if (!*set) + if (!(*set = set_new(trivial_hash_func, trivial_compare_func))) + return -ENOMEM; + + if ((r = set_put(*set, other)) < 0) + return r; + } + + 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" }, + { NULL, NULL, NULL, NULL } + }; + + char **t, **l; + int r; + + 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) + goto fail; + + return 0; + +fail: + + strv_free(l); + return 0; +} diff --git a/load-fragment.h b/load-fragment.h new file mode 100644 index 000000000..523426faf --- /dev/null +++ b/load-fragment.h @@ -0,0 +1,12 @@ +/*-*- Mode: C; c-basic-offset: 8 -*-*/ + +#ifndef fooloadfragmenthfoo +#define fooloadfragmenthfoo + +#include "name.h" + +/* Read service data from .desktop file style configuration fragments */ + +int name_load_fragment(Name *n); + +#endif