console-server: Respect DBus init failure
Given that the DBus interface is required by other OpenBMC applications,
don't ignore a failure to initialize it.
It's always possible to add a switch down the track to avoid
initializing the DBus interfaces, if desired.
Change-Id: I8aecf1a1cb06d021f374eaf0fd6893ddf3a9cc3c
Co-developed-by: Alexander Hansen <alexander.hansen@9elements.com>
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
diff --git a/console-dbus.c b/console-dbus.c
index 7968721..71dd0de 100644
--- a/console-dbus.c
+++ b/console-dbus.c
@@ -159,8 +159,8 @@
SD_BUS_VTABLE_END,
};
-void dbus_init(struct console *console,
- struct config *config __attribute__((unused)))
+int dbus_init(struct console *console,
+ struct config *config __attribute__((unused)))
{
char obj_name[dbus_obj_path_len];
char dbus_name[dbus_obj_path_len];
@@ -171,13 +171,13 @@
if (!console) {
warnx("Couldn't get valid console");
- return;
+ return -1;
}
r = sd_bus_default(&console->bus);
if (r < 0) {
warnx("Failed to connect to bus: %s", strerror(-r));
- return;
+ return -1;
}
/* Register support console interface */
@@ -186,7 +186,7 @@
if (bytes >= dbus_obj_path_len) {
warnx("Console id '%s' is too long. There is no enough space in the buffer.",
console->console_id);
- return;
+ return -1;
}
if (console->tty.type == TTY_DEVICE_UART) {
@@ -197,7 +197,7 @@
if (r < 0) {
warnx("Failed to register UART interface: %s",
strerror(-r));
- return;
+ return -1;
}
}
@@ -206,7 +206,7 @@
console_access_vtable, console);
if (r < 0) {
warnx("Failed to issue method call: %s", strerror(-r));
- return;
+ return -1;
}
bytes = snprintf(dbus_name, dbus_obj_path_len, DBUS_NAME,
@@ -214,7 +214,7 @@
if (bytes >= dbus_obj_path_len) {
warnx("Console id '%s' is too long. There is no enough space in the buffer.",
console->console_id);
- return;
+ return -1;
}
/* Finally register the bus name */
@@ -223,17 +223,19 @@
SD_BUS_NAME_REPLACE_EXISTING);
if (r < 0) {
warnx("Failed to acquire service name: %s", strerror(-r));
- return;
+ return -1;
}
fd = sd_bus_get_fd(console->bus);
if (fd < 0) {
warnx("Couldn't get the bus file descriptor");
- return;
+ return -1;
}
dbus_poller = POLLFD_DBUS;
console->pollfds[dbus_poller].fd = fd;
console->pollfds[dbus_poller].events = POLLIN;
+
+ return 0;
}