[systemd-devel] [PATCH/resend] systemctl: check the argument to -t for invalid values

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Wed Jun 6 06:58:41 PDT 2012


On 06/06/2012 02:48 PM, Kay Sievers wrote:
> On Wed, Jun 6, 2012 at 12:07 PM, Zbigniew Jędrzejewski-Szmek
> <zbyszek at in.waw.pl> wrote:
>> Systemctl accepted anything as the argument for -t, and simply said '0
>> units found'. It is better to catch this user error early.
>> ---
>> A small thing thing I noticed today.
>>
>>  src/systemctl/systemctl.c | 17 +++++++++++++++++
>>  1 file changed, 17 insertions(+)
>>
>> diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
>> index 66f4113..d353071 100644
>> --- a/src/systemctl/systemctl.c
>> +++ b/src/systemctl/systemctl.c
>> @@ -4325,6 +4325,19 @@ static int runlevel_help(void) {
>>         return 0;
>>  }
>>  +static int arg_type_ok(const char *type) {
>> +
>> +        static const char *types[] = {"service", "socket", "device",
>> "mount",
>> +                                      "swap", "automount", "target",
>> "path",
>> +                                      "timer", "snapshot"};
> 
> Instead of copying the valid strings, we should probably add a
> unit_type_table[] that maps the type enum to the strings and calls a
> DEFINE_STRING_TABLE_LOOKUP() function to resolve it.?
Sure, this sounds reasonable. But where should this table live:
the natural place would be unit.[ch], but systemctl is not linked
against that, and the .o file is fairly big. One option would be to move
the UnitType enums from unit.[ch] to unit-name.[ch], which is in shared/
and then add DEFINE_STRING_TABLE_LOOKUP.

?

Zbyszek


More information about the systemd-devel mailing list