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;
}
diff --git a/console-server.c b/console-server.c
index aec7a35..596e227 100644
--- a/console-server.c
+++ b/console-server.c
@@ -1007,7 +1007,10 @@
goto out_ringbuffer_fini;
}
- dbus_init(console, config);
+ rc = dbus_init(console, config);
+ if (rc) {
+ goto out_tty_fini;
+ }
handlers_init(console, config);
@@ -1015,6 +1018,7 @@
handlers_fini(console);
+out_tty_fini:
tty_fini(console);
out_ringbuffer_fini:
diff --git a/console-server.h b/console-server.h
index 3fd572c..3dc445e 100644
--- a/console-server.h
+++ b/console-server.h
@@ -239,8 +239,8 @@
int write_buf_to_fd(int fd, const uint8_t *buf, size_t len);
/* console-dbus API */
-void dbus_init(struct console *console,
- struct config *config __attribute__((unused)));
+int dbus_init(struct console *console,
+ struct config *config __attribute__((unused)));
/* socket-handler API */
int dbus_create_socket_consumer(struct console *console);