summaryrefslogtreecommitdiff
path: root/src/shared/conf-parser.h
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-05-27 01:39:12 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-05-31 11:09:41 +0900
commit2d1729ca3ff7d8ee51b12711411d15c3e22b9148 (patch)
treea179966f74cb5fab8b783bdecac8895e93e68ac3 /src/shared/conf-parser.h
parent0a9e36387049e25fd3829281e98cd9b74c7d81df (diff)
downloadsystemd-2d1729ca3ff7d8ee51b12711411d15c3e22b9148.tar.gz
conf-parser: introduce DEFINE_CONFIG_PARSE*() macros
This introduces several macros for defining config parsers. Also this fixes errno in DEFINE_CONFIG_PARSE_ENUM() and _ENUMV() and makes the log level lower when a duplicated item is specified to the settings parsed by the function defined by DEFINE_CONFIG_PARSE_ENUMV().
Diffstat (limited to 'src/shared/conf-parser.h')
-rw-r--r--src/shared/conf-parser.h84
1 files changed, 74 insertions, 10 deletions
diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h
index 0b0532d1ab..70d313d4eb 100644
--- a/src/shared/conf-parser.h
+++ b/src/shared/conf-parser.h
@@ -152,7 +152,65 @@ typedef enum Disabled {
DISABLED_EXPERIMENTAL,
} Disabled;
-#define DEFINE_CONFIG_PARSE_ENUM(function,name,type,msg) \
+#define DEFINE_CONFIG_PARSE(function, parser, msg) \
+ CONFIG_PARSER_PROTOTYPE(function) { \
+ int *i = data, r; \
+ \
+ assert(filename); \
+ assert(lvalue); \
+ assert(rvalue); \
+ assert(data); \
+ \
+ r = parser(rvalue); \
+ if (r < 0) { \
+ log_syntax(unit, LOG_ERR, filename, line, r, \
+ msg ", ignoring: %s", rvalue); \
+ return 0; \
+ } \
+ \
+ *i = r; \
+ return 0; \
+ }
+
+#define DEFINE_CONFIG_PARSE_PTR(function, parser, type, msg) \
+ CONFIG_PARSER_PROTOTYPE(function) { \
+ type *i = data; \
+ int r; \
+ \
+ assert(filename); \
+ assert(lvalue); \
+ assert(rvalue); \
+ assert(data); \
+ \
+ r = parser(rvalue, i); \
+ if (r < 0) \
+ log_syntax(unit, LOG_ERR, filename, line, r, \
+ msg ", ignoring: %s", rvalue); \
+ \
+ return 0; \
+ }
+
+#define DEFINE_CONFIG_PARSE_ENUM(function, name, type, msg) \
+ CONFIG_PARSER_PROTOTYPE(function) { \
+ type *i = data, x; \
+ \
+ assert(filename); \
+ assert(lvalue); \
+ assert(rvalue); \
+ assert(data); \
+ \
+ x = name##_from_string(rvalue); \
+ if (x < 0) { \
+ log_syntax(unit, LOG_ERR, filename, line, 0, \
+ msg ", ignoring: %s", rvalue); \
+ return 0; \
+ } \
+ \
+ *i = x; \
+ return 0; \
+ }
+
+#define DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(function, name, type, default_value, msg) \
CONFIG_PARSER_PROTOTYPE(function) { \
type *i = data, x; \
\
@@ -161,8 +219,14 @@ typedef enum Disabled {
assert(rvalue); \
assert(data); \
\
- if ((x = name##_from_string(rvalue)) < 0) { \
- log_syntax(unit, LOG_ERR, filename, line, -x, \
+ if (isempty(rvalue)) { \
+ *i = default_value; \
+ return 0; \
+ } \
+ \
+ x = name##_from_string(rvalue); \
+ if (x < 0) { \
+ log_syntax(unit, LOG_ERR, filename, line, 0, \
msg ", ignoring: %s", rvalue); \
return 0; \
} \
@@ -171,7 +235,7 @@ typedef enum Disabled {
return 0; \
}
-#define DEFINE_CONFIG_PARSE_ENUMV(function,name,type,invalid,msg) \
+#define DEFINE_CONFIG_PARSE_ENUMV(function, name, type, invalid, msg) \
CONFIG_PARSER_PROTOTYPE(function) { \
type **enums = data, x, *ys; \
_cleanup_free_ type *xs = NULL; \
@@ -198,17 +262,17 @@ typedef enum Disabled {
return -ENOMEM; \
\
if ((x = name##_from_string(en)) < 0) { \
- log_syntax(unit, LOG_ERR, filename, line, \
- -x, msg ", ignoring: %s", en); \
+ log_syntax(unit, LOG_ERR, filename, line, 0, \
+ msg ", ignoring: %s", en); \
continue; \
} \
\
for (ys = xs; x != invalid && *ys != invalid; ys++) { \
if (*ys == x) { \
- log_syntax(unit, LOG_ERR, filename, \
- line, -x, \
- "Duplicate entry, ignoring: %s", \
- en); \
+ log_syntax(unit, LOG_NOTICE, filename, \
+ line, 0, \
+ "Duplicate entry, ignoring: %s", \
+ en); \
x = invalid; \
} \
} \