blob: 1f47026b952bdd665f81af476ade374c07b4c922 [file] [log] [blame]
Andrew Jeffery4fe996c2018-02-27 12:16:48 +10301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +11003
4#define _GNU_SOURCE
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +11005#include <systemd/sd-bus.h>
6
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +11007#include "common.h"
8#include "dbus.h"
Andrew Jeffery68023072018-08-06 10:08:11 +09309#include "mbox.h"
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110010#include "mboxd_dbus.h"
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110011
Andrew Jefferyba0bbab2018-08-06 09:43:57 +093012int mboxd_dbus_init(struct mbox_context *context)
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110013{
14 int rc;
15
16 rc = sd_bus_default_system(&context->bus);
17 if (rc < 0) {
18 MSG_ERR("Failed to connect to the system bus: %s\n",
19 strerror(-rc));
20 return rc;
21 }
22
Andrew Jeffery68023072018-08-06 10:08:11 +093023 rc = control_legacy_init(context);
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110024 if (rc < 0) {
Andrew Jeffery68023072018-08-06 10:08:11 +093025 MSG_ERR("Failed to initialise legacy DBus interface: %s\n",
26 strerror(-rc));
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110027 return rc;
28 }
29
30 rc = sd_bus_get_fd(context->bus);
31 if (rc < 0) {
32 MSG_ERR("Failed to get bus fd: %s\n", strerror(-rc));
33 return rc;
34 }
35
36 context->fds[DBUS_FD].fd = rc;
37
38 return 0;
39}
40
Andrew Jefferyba0bbab2018-08-06 09:43:57 +093041void mboxd_dbus_free(struct mbox_context *context)
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110042{
Andrew Jeffery68023072018-08-06 10:08:11 +093043 control_legacy_free(context);
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110044 sd_bus_unref(context->bus);
45}