Signed-off-by: Anders Selhammer <[email protected]>
---
config.c | 45 ++++++++++++++++++++++++++++++++++-----------
config.h | 10 ++++++++--
2 files changed, 42 insertions(+), 13 deletions(-)
diff --git a/config.c b/config.c
index 2321310..b8e7977 100644
--- a/config.c
+++ b/config.c
@@ -1080,25 +1080,48 @@ int config_set_section_int(struct config *cfg, const
char *section,
return 0;
}
-int config_set_string(struct config *cfg, const char *option,
- const char *val)
+int config_set_section_string(struct config *cfg, const char *section,
+ const char *option, const char *val)
{
- struct config_item *ci = config_find_item(cfg, NULL, option);
+ struct config_item *cgi, *dst;
- if (!ci || ci->type != CFG_TYPE_STRING) {
+ cgi = config_find_item(cfg, NULL, option);
+ if (!cgi || cgi->type != CFG_TYPE_STRING) {
pr_err("bug: config option %s missing or invalid!", option);
return -1;
}
- ci->flags |= CFG_ITEM_LOCKED;
- if (ci->flags & CFG_ITEM_DYNSTR) {
- free(ci->val.s);
+
+ if (!section) {
+ cgi->flags |= CFG_ITEM_LOCKED;
+ if (cgi->flags & CFG_ITEM_DYNSTR) {
+ free(cgi->val.s);
+ }
+ cgi->val.s = strdup(val);
+ if (!cgi->val.s) {
+ pr_err("low memory");
+ return -1;
+ }
+ cgi->flags |= CFG_ITEM_DYNSTR;
+ pr_debug("locked item global.%s as '%s'", option, cgi->val.s);
+ return 0;
+ }
+ /* Create or update this port specific item. */
+ dst = config_section_item(cfg, section, option);
+ if (!dst) {
+ dst = config_item_alloc(cfg, section, option, cgi->type);
+ if (!dst) {
+ return -1;
+ }
+ }
+ if (dst->flags & CFG_ITEM_DYNSTR) {
+ free(dst->val.s);
}
- ci->val.s = strdup(val);
- if (!ci->val.s) {
+ dst->val.s = strdup(val);
+ if (!dst->val.s) {
pr_err("low memory");
return -1;
}
- ci->flags |= CFG_ITEM_DYNSTR;
- pr_debug("locked item global.%s as '%s'", option, ci->val.s);
+ dst->flags |= CFG_ITEM_DYNSTR;
+ pr_debug("section item %s.%s now %s", section, option, dst->val.s);
return 0;
}
diff --git a/config.h b/config.h
index f237fb2..c335a19 100644
--- a/config.h
+++ b/config.h
@@ -97,7 +97,13 @@ static inline int config_set_int(struct config *cfg,
return config_set_section_int(cfg, NULL, option, val);
}
-int config_set_string(struct config *cfg, const char *option,
- const char *val);
+int config_set_section_string(struct config *cfg, const char *section,
+ const char *option, const char *val);
+
+static inline int config_set_string(struct config *cfg, const char *option,
+ const char *val)
+{
+ return config_set_section_string(cfg, NULL, option, val);
+}
#endif
--
1.8.3.1
_______________________________________________
Linuxptp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel