Skip to content

Support for config fragments (conf.d style dirs)

Manuel A. Fernandez Montecelo linux-bluetooth 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest1 patch 2 repliesIn review
  2. v21 patch 3 repliesSuperseded
  3. v11 patch 5 repliesSuperseded

Changes in v3 from the cover letter

- Minor rephrasing of commit message, fixing conf paths and others
- Emit DBG message if network.conf fails to parse (silently ignored now)
- Add err parameter to confd_process_config(), modify returned message to include file that fails to parse, and check returned errors from calling sites.
- On the calling sites, next after loading the base config file, act on errors in the same way as an err when loading each base config file (the effect in all cases is to use the default hardcoded values, when config is not present / not loadable)

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/1Support for config fragments (conf.d style dirs)Makefile.am profiles/input/hog.c profiles/input/manager.c +4 more+328 -02 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH BlueZ v3 0/1] Support for config fragments (conf.d style dirs)

Support config fragments, to read config from conf.d directories.

This is commonly supported by other tools, as an extension of the main config file(s). It is useful and convenient in several situations, for example:

* distributions can set different values from the defaults shipped upstream, without having to modify the config file

* different packages or config-management tools can change config just by adding, removing or modifying files in that directory; instead of editing the main config files

---
Notes on v3 non-changes:

I considered other changes for v3 as requested in message
https://marc.info/?l=linux-bluetooth&m=176557679130526 , but as explained in my next reply
(https://marc.info/?l=linux-bluetooth&m=176558570102172&w=2), I didn't understand part of the request, so in the meantime I tried my best to interpret, to make some progress.

Experimenting and pondering for quite a while about the question of how to do the loading and parsing (as discussed in those messages), I came to the conclusion that in general it makes sense to keep the main idea of this patches' implementation:
* to consider the config fragments (files in conf.d) part of the config in each area (an extension of main.conf, input.conf, etc);
* treat the whole set as a single unit, loading base and then one fragment after another in place for that area (which means also parsing the config file in text to convert it to a key_file in mem);
* and only after an area is complete and all bits are in, invoke parse_config(main_conf)-like functions to transfer values to code variables, and do it only once.

Problems mentioned in the message, like wrong groups in the base main.conf being then possible in the fragments, should not have a bad effect in practice -- there are specific checks with hardcoded "valid groups" and "keys" for each area. And if the values of the keys overriden are not valid, it will also be noticed later in the processing.

Another problem, perhaps more theoretical (I don't think that it will have much impact in the real-world, but nevertheless somewhat wasteful effort), is to do the loading and parsing over and over. parse_config()-like functions are trying to find values for all possible keys, that in case of fragments typically do not exist -- because fragments typically only contain one, or perhaps a handful of key=values only. As I see it, the pre-existing code is based on the idea that the key_file representing each section (main.conf, input.conf, etc) contains all the config for that area, and it only loads and parses once each area.

As an additional, more practical problem, for example main.conf (as represented in a key_file) is preserved for the whole lifetime of the program running, and there's the function:

  GKeyFile *btd_get_main_conf(void) {
          return main_conf;

}

Then plugins/policy.c invokes this function and acts upon the values. I think that the returned value of that function should include the extra config fragments, and not only exclusively the representation of the original main.conf file, both in theoretical terms but also in practice -- because otherwise this policy.c would not be able to act upon config coming via fragments.

So, all in all, I think that merging all loaded config in a single key_file, and then transferring those values to program variables only once, is roughly the correct approach.

But I'm completely open to change it if you are still not convinced or see other problems of this approach. And please clarify your previous message if I misunderstood.

---
Changes in v3:
- Minor rephrasing of commit message, fixing conf paths and others
- Emit DBG message if network.conf fails to parse (silently ignored now)
- Add err parameter to confd_process_config(), modify returned message to include file that fails to parse, and check returned errors from calling sites.
- On the calling sites, next after loading the base config file, act on errors in the same way as an err when loading each base config file (the effect in all cases is to use the default hardcoded values, when config is not present / not loadable)

Changes in v2:
- Use alternate functions to not change (raise) required Glib version
- Reformat code (styling)

---
Manuel A. Fernandez Montecelo (1):
Support for config fragments (conf.d style dirs)

 Makefile.am                |   1 +
 profiles/input/hog.c       |   9 ++
 profiles/input/manager.c   |   9 ++
 profiles/network/manager.c |   9 ++
 src/conf_d.c               | 208 +++++++++++++++++++++++++++++++++++++
 src/conf_d.h               |  83 +++++++++++++++
 src/main.c                 |   9 ++
 7 files changed, 328 insertions(+)
 create mode 100644 src/conf_d.c
 create mode 100644 src/conf_d.h
Signature · 1 line
2.51.0