[PATCH 1/2] server: Allow handlers to fail init
Joel Stanley
joel at jms.id.au
Thu Apr 28 17:16:03 AEST 2016
On Thu, Apr 28, 2016 at 2:49 PM, Jeremy Kerr <jk at ozlabs.org> wrote:
> If a handler fails its init, we don't want to invoke its callbacks.
>
> This change adds a flag to struct handlers, to indicate whether a
> handler is active (ie, init() has returned success). Only active
> handlers are used.
>
> We also change the handler list output to indicate which are active.
Looks good. A minor comment below.
> Signed-off-by: Jeremy Kerr <jk at ozlabs.org>
Reviewed-by: Joel Stanley <joel at jms.id.au>
> ---
> console-server.c | 17 ++++++++++++-----
> console-server.h | 2 ++
> 2 files changed, 14 insertions(+), 5 deletions(-)
>
> diff --git a/console-server.c b/console-server.c
> index f8feb52..45dd07a 100644
> --- a/console-server.c
> +++ b/console-server.c
> @@ -257,7 +257,7 @@ static void handlers_init(struct console *console, struct config *config)
> {
> extern struct handler *__start_handlers, *__stop_handlers;
> struct handler *handler;
> - int i;
> + int i, rc;
>
> console->n_handlers = &__stop_handlers - &__start_handlers;
> console->handlers = &__start_handlers;
> @@ -268,10 +268,14 @@ static void handlers_init(struct console *console, struct config *config)
> for (i = 0; i < console->n_handlers; i++) {
> handler = console->handlers[i];
>
> - printf(" %s\n", handler->name);
> -
> + rc = 0;
> if (handler->init)
> - handler->init(handler, console, config);
> + rc = handler->init(handler, console, config);
you could do handler->active = handler-init(), and drop the rc all together.
> +
> + handler->active = rc == 0;
> +
> + printf(" %s [%sactive]\n", handler->name,
> + handler->active ? "" : "in");
> }
> }
More information about the openbmc
mailing list