[systemd-devel] [PATCH] systemd-analyze: filter dot output with a regular expression

Lukasz Stelmach stlman at poczta.fm
Mon Mar 25 13:19:55 PDT 2013


W dniu 25.03.2013 16:48, Lennart Poettering pisze:
> On Sun, 24.03.13 13:32, Łukasz Stelmach (stlman at poczta.fm) wrote:
> 
>> Make "systemd-analyze dot" output only lines matching a regular
>> expression passed on the command line. Without the regular expression
>> print everything.
> 
> So far we mostly used globs everywhere in system. Does it really make
> sense to use regexes here?
> 
> I mean, unit file names on purpose are "file-name like", and generally
> even show up in the file system, so it sounds more natural to me to use
> fnmatch here?

Indeed fnmatch() is better for matching unit names, however, I match the
whole line:

        "multi-user.target"->"basic.target" [color="green"];

rather than the the unit names. To quickly match the line above I use
"target.*target". A glob that does tha same is "*target*target*" not as
nice, is it? (This is because globs are implicitly anchored at the
beginning of strings while regexps are not)

I could use globs and match unit names but then the logic would have to
be a bit more complicated. If there is one glob given on the command
line then match either of the units. If two, then the first matches s
and the other c. With regexp this you can match the colour too with no
extra effort.

I am not quite sure fnmatch() with these constraints is better? RFC.

>>          static const char * const colors[] = {
>>                  "Requires",              "[color=\"black\"]",
>> @@ -591,6 +594,7 @@ static int graph_one_property(const char *name, const char *prop, DBusMessageIte
>>                  "After",                 "[color=\"green\"]"
>>          };
>>  
>> +        char buf[1024];
> 
> We generally avoid using fixed size strings like this. Use dynamic
> memory for this if you can... i.e. asprintf(), and consider freeing it
> with _cleanup_free_...

Cool! Done ;-)

-- 
Było mi bardzo miło.               Czwarta pospolita klęska, [...]
>Łukasz<                 Już nie katolicka lecz złodziejska.  (c)PP


More information about the systemd-devel mailing list