swanctl: Check for conflicts with shared options when registering commands
Also suppress errors when pre-processing shared options (this was missing here but already used in pki).
This commit is contained in:
@@ -185,6 +185,8 @@ static bool process_common_opts(bool init)
|
|||||||
int prevoptind = optind;
|
int prevoptind = optind;
|
||||||
bool success = TRUE;
|
bool success = TRUE;
|
||||||
|
|
||||||
|
/* don't report any errors during this pre-processing */
|
||||||
|
opterr = 0;
|
||||||
while (TRUE)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
switch (getopt_long(argc, argv, command_optstring, command_opts, NULL))
|
switch (getopt_long(argc, argv, command_optstring, command_opts, NULL))
|
||||||
@@ -243,6 +245,16 @@ void command_register(command_t command)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (i = 0; i < countof(shared_options); i++)
|
||||||
|
{
|
||||||
|
if (shared_options[i].op == command.op)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "unable to register command --%s, short option "
|
||||||
|
"-%c conflicts with --%s\n", command.cmd, command.op,
|
||||||
|
shared_options[i].name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cmds[registered] = command;
|
cmds[registered] = command;
|
||||||
/* append default options, but not to --help */
|
/* append default options, but not to --help */
|
||||||
|
|||||||
Reference in New Issue
Block a user