[systemd-devel] Configuration file parser library

Chris Morgan chmorgan at gmail.com
Mon Nov 11 12:29:57 PST 2013


On Sun, Nov 10, 2013 at 4:54 PM, Lennart Poettering
<lennart at poettering.net> wrote:
> On Sat, 09.11.13 09:02, Chris Morgan (chmorgan at gmail.com) wrote:
>
>> Hello.
>>
>> I wanted to implement a configuration file format for an application of
>> mine that uses a similar format to what systemd uses. I was wondering if
>> the parser used today was from an external library. I googled a bit but
>> wasn't able to dig anything up. I haven't looked at the code in detail yet.
>
> We use our homegrown code for parsing configuration files. It's fancier
> these days than it used to be (even using gperf perfect hash tables for
> key lookup), but it's nothing I'd ever want to see used outside of our
> specific domain of low-level system components.
>
> Use GLib's GKeyFile in other projects. We try to stay compatible with
> it, however only in one way, i.e. so that GKeyFile can be used to write
> configuration files for systemd and has access to all features of
> systemd, however, not all systemd configuration files can be read by
> GKeyFile. (the reason for that is mostly that we allow multiple
> assignments to the same key, which GKeyFile (currently) doesn't allow,
> and more suggests pushing a serialization of multiple assignments into
> the same line, which is really difficult to read though as we believe,
> and systemd runs into this quite often).
>
> Lennart
>
> --
> Lennart Poettering, Red Hat


To keep it short:

I don't see that GKeyFile supports nested groups. For my users I was
hoping to present something like:

[Clients]

    [ObjectNameHere]
    type='value'

   [AnotherObjectHere]
   type='value'

[Services]
    [ObjectNameHere]
    ...



with the hope that on the parsing side I could iterate over the
entries under 'Services' and then repeat under 'Clients'.

I *could* put a key under each entry to define whether it is a client
or a service but this seemed less naturally ordered.

Anyway, this is off-topic for systemd,

I've gotten several good responses here and I appreciate it.

Chris


More information about the systemd-devel mailing list