Andrew Jeffery | 4fe996c | 2018-02-27 12:16:48 +1030 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (C) 2018 IBM Corp. |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 3 | |
| 4 | #define _GNU_SOURCE |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 5 | #include <systemd/sd-bus.h> |
| 6 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 7 | #include "common.h" |
| 8 | #include "dbus.h" |
Andrew Jeffery | 6802307 | 2018-08-06 10:08:11 +0930 | [diff] [blame^] | 9 | #include "mbox.h" |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 10 | #include "mboxd_dbus.h" |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 11 | |
Andrew Jeffery | ba0bbab | 2018-08-06 09:43:57 +0930 | [diff] [blame] | 12 | int mboxd_dbus_init(struct mbox_context *context) |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 13 | { |
| 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 Jeffery | 6802307 | 2018-08-06 10:08:11 +0930 | [diff] [blame^] | 23 | rc = control_legacy_init(context); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 24 | if (rc < 0) { |
Andrew Jeffery | 6802307 | 2018-08-06 10:08:11 +0930 | [diff] [blame^] | 25 | MSG_ERR("Failed to initialise legacy DBus interface: %s\n", |
| 26 | strerror(-rc)); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 27 | 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 Jeffery | ba0bbab | 2018-08-06 09:43:57 +0930 | [diff] [blame] | 41 | void mboxd_dbus_free(struct mbox_context *context) |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 42 | { |
Andrew Jeffery | 6802307 | 2018-08-06 10:08:11 +0930 | [diff] [blame^] | 43 | control_legacy_free(context); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 44 | sd_bus_unref(context->bus); |
| 45 | } |