[systemd-devel] [RFC][PATCH] conf-parser: allow instanced sections

Tom Gundersen teg at jklm.no
Tue Nov 19 13:20:47 PST 2013


On Tue, Nov 19, 2013 at 7:07 PM, Colin Guthrie <gmane at colin.guthr.ie> wrote:
> 'Twas brillig, and Tom Gundersen at 19/11/13 16:57 did gyre and gimble:
>> This will treat [Section:bar], [Section:foo], and [Section:baz],
>> as [Section], but pass on the full section name to the options parser
>> so it can treat them separately.
>
> What is the semantics here? (I should probably know as you've likely
> posted it already!)
>
> e.g. I've seen the following semantics before for ini-style parsing:
>
> [database]
> database.adapter         = pdo_mysql
> database.params.host     = db.dev
> database.params.username = ninja
> database.params.password = dressedinblack
>
> [mydb : database]
> database.params.dbname   = mydatabase
>
> This basically means the "mydb" section inherits from the "database"
> section and only changes what it needs.
>
> It seems you're using using this slightly differently in that you'll have a:
>
> [General]
> Address=xyz
>
> and then a
>
> [Address:xyz]
>
> section? i.e. the instances section actually inherits from an earlier value?

What I have in mind (though it is not dictated by this patch) is
something different (first proposed by Lennart in an earlier thread):

[Network]
Address=192.168.0.1/24
Address=192.168.0.2/24
Gateway=192.168.1.1

[Address:oneaddress]
Address=192.168.0.3/24
Label=three
Peer=192.168.1.1

[Address:anotheraddress]
Address=192.168.0.4/24
Label=four

In this case we'll configure four addresses. The two first ones could
also have been expressed as:

[Address:foo]
Address=192.168.0.1/24

[Address:bar]
Address=192.168.0.2/24,

but we allow putting them directly in the [Network] section rather
than in a named [Address] section as a shorthand.

Notice that if we simply did

[Address]
Address=192.168.0.3/24
Label=three
Peer=192.168.1.1

[Address]
Address=192.168.0.4/24
Label=four,

that wouldn't work as it is (at least currently) equivalent to

[Address]
Address=192.168.0.3/24
Label=three
Peer=192.168.1.1
Address=192.168.0.4/24
Label=four,

which is why we need to give the secitons unique names.

> If so then I doubt the semantics here can be generalised to this other
> example in which case my comment is rather moot!
>
> So take this comment with a pinch of salt :D
>
>
>> @@ -253,17 +255,27 @@ static int parse_line(const char* unit,
>>                  if (!n)
>>                          return -ENOMEM;
>>
>> -                if (sections && !nulstr_contains(sections, n)) {
>> +                e = strchr(n, ':');
>> +                if (e)
>> +                        m = strndup(n, e - n);
>> +                else
>> +                        m = strdup(n);
>> +
>> +                if (sections && !nulstr_contains(sections, m)) {
>
> Do you want to do some whitespace trimming here perhaps? e.g. if n is
> "Foo :bar" or "Foo : bar" or "Foo: bar" etc.
>
> being silently tolerant of this is probably most sensible I guess.

Yes, that's probably a good idea. Thanks.

-t


More information about the systemd-devel mailing list