server: Allow handlers to fail init

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.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
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 @@
 {
 	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 @@
 	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);
+
+		handler->active = rc == 0;
+
+		printf("  %s [%sactive]\n", handler->name,
+				handler->active ? "" : "in");
 	}
 }
 
@@ -282,7 +286,7 @@
 
 	for (i = 0; i < console->n_handlers; i++) {
 		handler = console->handlers[i];
-		if (handler->fini)
+		if (handler->fini && handler->active)
 			handler->fini(handler);
 	}
 }
@@ -297,6 +301,9 @@
 	for (i = 0; i < console->n_handlers; i++) {
 		handler = console->handlers[i];
 
+		if (!handler->active)
+			continue;
+
 		if (!handler->data_in)
 			continue;