[systemd-devel] [RFC][PATCH] conf-parser: allow instanced sections
Tom Gundersen
teg at jklm.no
Tue Nov 19 08:57:11 PST 2013
This will treat [Section:bar], [Section:foo], and [Section:baz],
as [Section], but pass on the full section name to the options parser
so it can treat them separately.
---
This is needed so we can add [Address:xxx] and [Route:xxx] sections
ot .network files.
src/shared/conf-parser.c | 28 +++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index efd2147..4f9cb98 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -156,6 +156,7 @@ static int next_assignment(const char *unit,
ConfigItemLookup lookup,
void *table,
const char *section,
+ const char *section_instance,
const char *lvalue,
const char *rvalue,
bool relaxed,
@@ -178,8 +179,8 @@ static int next_assignment(const char *unit,
if (r > 0) {
if (func)
- return func(unit, filename, line, section, lvalue, ltype,
- rvalue, data, userdata);
+ return func(unit, filename, line, section_instance, lvalue,
+ ltype, rvalue, data, userdata);
return 0;
}
@@ -202,6 +203,7 @@ static int parse_line(const char* unit,
bool relaxed,
bool allow_include,
char **section,
+ char **section_instance,
char *l,
void *userdata) {
@@ -238,7 +240,7 @@ static int parse_line(const char* unit,
if (*l == '[') {
size_t k;
- char *n;
+ char *n, *m;
k = strlen(l);
assert(k > 0);
@@ -253,17 +255,27 @@ static int parse_line(const char* unit,
if (!n)
return -ENOMEM;
- if (sections && !nulstr_contains(sections, n)) {
+ e = strchr(n, ':');
+ if (e)
+ m = strndup(n, e - n);
+ else
+ m = strdup(n);
+
+ if (sections && !nulstr_contains(sections, m)) {
if (!relaxed)
log_syntax(unit, LOG_WARNING, filename, line, EINVAL,
- "Unknown section '%s'. Ignoring.", n);
+ "Unknown section '%s'. Ignoring.", m);
free(n);
+ free(m);
*section = NULL;
+ *section_instance = NULL;
} else {
free(*section);
- *section = n;
+ free(*section_instance);
+ *section = m;
+ *section_instance = n;
}
return 0;
@@ -293,6 +305,7 @@ static int parse_line(const char* unit,
lookup,
table,
*section,
+ *section_instance,
strstrip(l),
strstrip(e),
relaxed,
@@ -310,7 +323,7 @@ int config_parse(const char *unit,
bool allow_include,
void *userdata) {
- _cleanup_free_ char *section = NULL, *continuation = NULL;
+ _cleanup_free_ char *section = NULL, *section_instance = NULL, *continuation = NULL;
_cleanup_fclose_ FILE *ours = NULL;
unsigned line = 0;
int r;
@@ -381,6 +394,7 @@ int config_parse(const char *unit,
relaxed,
allow_include,
§ion,
+ §ion_instance,
p,
userdata);
free(c);
--
1.8.4.2
More information about the systemd-devel
mailing list