[systemd-devel] [PATCH 2/3] conf-parser: add "ignored sections" parameter
Zbigniew Jędrzejewski-Szmek
zbyszek at in.waw.pl
Wed May 1 05:53:45 PDT 2013
config_parse will ignore settings specified in 'ignored_sections'. The purpose
is being able to share a config file between two different modules (e.g. systemd
and systemd-sleep) without both understanding all sections. Each new section
has only to be added to either 'sections' or 'ignored_sections' in all modules
which parse the same config file.
No functional change.
---
src/bootchart/bootchart.c | 4 ++--
src/core/load-dropin.c | 6 +++---
src/core/load-fragment.c | 2 +-
src/core/main.c | 3 ++-
src/journal/journald-server.c | 2 +-
src/login/logind.c | 2 +-
src/shared/conf-parser.c | 10 ++++++++--
src/shared/conf-parser.h | 1 +
src/shared/install.c | 2 +-
src/tty-ask-password-agent/tty-ask-password-agent.c | 3 ++-
10 files changed, 22 insertions(+), 13 deletions(-)
diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c
index b733191..2048f8a 100644
--- a/src/bootchart/bootchart.c
+++ b/src/bootchart/bootchart.c
@@ -123,8 +123,8 @@ static void parse_conf(void) {
if (!f)
return;
- r = config_parse(NULL, BOOTCHART_CONF, f,
- NULL, config_item_table_lookup, (void*) items, true, false, NULL);
+ r = config_parse(NULL, BOOTCHART_CONF, f, NULL, NULL,
+ config_item_table_lookup, (void*) items, true, false, NULL);
if (r < 0)
log_warning("Failed to parse configuration file: %s", strerror(-r));
diff --git a/src/core/load-dropin.c b/src/core/load-dropin.c
index a877e66..3044e9f 100644
--- a/src/core/load-dropin.c
+++ b/src/core/load-dropin.c
@@ -206,12 +206,12 @@ int unit_load_dropin(Unit *u) {
}
u->dropin_paths = unit_find_dropin_paths(u);
- if (! u->dropin_paths)
+ if (!u->dropin_paths)
return 0;
STRV_FOREACH(f, u->dropin_paths) {
- r = config_parse(u->id, *f, NULL,
- UNIT_VTABLE(u)->sections, config_item_perf_lookup,
+ r = config_parse(u->id, *f, NULL, UNIT_VTABLE(u)->sections, NULL,
+ config_item_perf_lookup,
(void*) load_fragment_gperf_lookup, false, false, u);
if (r < 0)
return r;
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index e2015ed..99e7c5e 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -2268,7 +2268,7 @@ static int load_from_path(Unit *u, const char *path) {
u->load_state = UNIT_MASKED;
else {
/* Now, parse the file contents */
- r = config_parse(u->id, filename, f, UNIT_VTABLE(u)->sections,
+ r = config_parse(u->id, filename, f, UNIT_VTABLE(u)->sections, NULL,
config_item_perf_lookup,
(void*) load_fragment_gperf_lookup, false, true, u);
if (r < 0)
diff --git a/src/core/main.c b/src/core/main.c
index 22cec4e..1748722 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -678,7 +678,8 @@ static int parse_config_file(void) {
return 0;
}
- r = config_parse(NULL, fn, f, "Manager\0", config_item_table_lookup, (void*) items, false, false, NULL);
+ r = config_parse(NULL, fn, f, "Manager\0", NULL,
+ config_item_table_lookup, (void*) items, false, false, NULL);
if (r < 0)
log_warning("Failed to parse configuration file: %s", strerror(-r));
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 1b5a22b..0c01fa1 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -1286,7 +1286,7 @@ static int server_parse_config_file(Server *s) {
return -errno;
}
- r = config_parse(NULL, fn, f, "Journal\0", config_item_perf_lookup,
+ r = config_parse(NULL, fn, f, "Journal\0", NULL, config_item_perf_lookup,
(void*) journald_gperf_lookup, false, false, s);
if (r < 0)
log_warning("Failed to parse configuration file: %s", strerror(-r));
diff --git a/src/login/logind.c b/src/login/logind.c
index 5a39440..4dede27 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -1698,7 +1698,7 @@ static int manager_parse_config_file(Manager *m) {
return -errno;
}
- r = config_parse(NULL, fn, f, "Login\0", config_item_perf_lookup,
+ r = config_parse(NULL, fn, f, "Login\0", NULL, config_item_perf_lookup,
(void*) logind_gperf_lookup, false, false, m);
if (r < 0)
log_warning("Failed to parse configuration file: %s", strerror(-r));
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index 2303d9a..623b503 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -196,6 +196,7 @@ static int parse_line(const char* unit,
const char *filename,
unsigned line,
const char *sections,
+ const char *ignored_sections,
ConfigItemLookup lookup,
void *table,
bool relaxed,
@@ -232,7 +233,7 @@ static int parse_line(const char* unit,
if (!fn)
return -ENOMEM;
- return config_parse(unit, fn, NULL, sections, lookup, table, relaxed, false, userdata);
+ return config_parse(unit, fn, NULL, sections, ignored_sections, lookup, table, relaxed, false, userdata);
}
if (*l == '[') {
@@ -252,7 +253,10 @@ static int parse_line(const char* unit,
if (!n)
return -ENOMEM;
- if (sections && !nulstr_contains(sections, n)) {
+ if (ignored_sections && nulstr_contains(ignored_sections, n)) {
+ free(n);
+ *section = NULL;
+ } else if (sections && !nulstr_contains(sections, n)) {
if (!relaxed)
log_syntax(unit, LOG_WARNING, filename, line, EINVAL,
@@ -303,6 +307,7 @@ int config_parse(const char *unit,
const char *filename,
FILE *f,
const char *sections,
+ const char *ignored_sections,
ConfigItemLookup lookup,
void *table,
bool relaxed,
@@ -375,6 +380,7 @@ int config_parse(const char *unit,
filename,
++line,
sections,
+ ignored_sections,
lookup,
table,
relaxed,
diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h
index 08428a5..3628bf5 100644
--- a/src/shared/conf-parser.h
+++ b/src/shared/conf-parser.h
@@ -84,6 +84,7 @@ int config_parse(const char *unit,
const char *filename,
FILE *f,
const char *sections, /* nulstr */
+ const char *ignored_sections, /* nulstr */
ConfigItemLookup lookup,
void *table,
bool relaxed,
diff --git a/src/shared/install.c b/src/shared/install.c
index edf4d2a..fda683b 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -1014,7 +1014,7 @@ static int unit_file_load(
return -ENOMEM;
}
- r = config_parse(NULL, path, f, NULL,
+ r = config_parse(NULL, path, f, NULL, NULL,
config_item_table_lookup, (void*) items, true, true, info);
if (r < 0)
return r;
diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c
index f463662..48c258c 100644
--- a/src/tty-ask-password-agent/tty-ask-password-agent.c
+++ b/src/tty-ask-password-agent/tty-ask-password-agent.c
@@ -275,7 +275,8 @@ static int parse_password(const char *filename, char **wall) {
return -errno;
}
- r = config_parse(NULL, filename, f, NULL, config_item_table_lookup, (void*) items, true, false, NULL);
+ r = config_parse(NULL, filename, f, NULL, NULL,
+ config_item_table_lookup, (void*) items, true, false, NULL);
if (r < 0) {
log_error("Failed to parse password file %s: %s", filename, strerror(-r));
goto finish;
--
1.8.2.562.g931e949
More information about the systemd-devel
mailing list