[LiSA-Devel] CLI_EX_* significance/usage

Radu Rendec radu.rendec at mindbit.ro
Tue Mar 12 11:25:16 EET 2013


On Tue, 2013-03-12 at 10:16 +0200, Andreea-Cristina Hodea wrote:
> I've fixed the following in cli/command/config_if.c:
> -      if_change_addr(cmd, if_addr->ifindex, if_addr->inet,
> if_addr->prefixlen, 0, NULL);
> -      // FIXME check return value of if_change_addr()
> +      if (if_change_addr(cmd, if_addr->ifindex, if_addr->inet,
> if_addr->prefixlen, 0, NULL) < 0) {
> +        ret = CLI_EX_REJECTED;
> +        goto out_cleanup;
> +      }

The patch looks fine to me. Maybe it would be nice to also set an error
string using EX_STATUS_REASON(), but that's really not important.

> but I'm not quite sure when a handler should return CLI_EX_REJECTED
> versus CLI_EX_WARNING. If we are here, when/where would CLI_EX_NOTIMPL
> aplly?

There is no rule about using either CLI_EX_WARNING or CLI_EX_REJECTED.
When we first implemented the CLI, we tried to make it as similar as
possible to the Cisco CLI, so we just "warning" vs. "rejected" in the
same way as they did.

Looking at the code in cli/command/config.c, I can see we're using
CLI_EX_REJECTED for all cases where something goes wrong and we cannot
continue executing the command.

I guess "rejected" should be used when we cannot execute the command at
all and "warning" should be used when something is executed, but it may
not be exactly what the user wanted, due to various reasons.

Going back to your question, CLI_EX_NOTIMPL is defined in cli/cli.h, but
neither handled nor used anywhere. I believe you can just remove it from
cli.h and forget about it.

To get a better picture of this, take a look at rlshell_exec() in
cli/rlshell.c

> Also, if removing one of the addresses fails, should the handler
> continue to try removing the other addresses and just set ret
> correspondingly?

This is a good question. I would say yes, but in this case the user
should get a warning if only some of the addresses could not be removed
and a "command rejected" if no address could be removed at all.

Radu




More information about the LiSA-Devel mailing list