Skip to content

Commit e3816cd

Browse files
authored
Merge pull request #542 from CodeConstruct/dev/mi-libdbus
MI: switch from libsdbus to libdbus
2 parents 1e298f8 + e7ea8c1 commit e3816cd

5 files changed

Lines changed: 222 additions & 216 deletions

File tree

examples/meson.build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ executable(
4040
include_directories: [incdir, internal_incdir]
4141
)
4242

43-
if libsystemd_dep.found()
43+
if libdbus_dep.found()
4444
executable(
4545
'mi-conf',
4646
['mi-conf.c'],
47-
dependencies: [libnvme_mi_dep, libsystemd_dep],
47+
dependencies: [libnvme_mi_dep, libdbus_dep],
4848
include_directories: [incdir, internal_incdir]
4949
)
5050
endif

examples/mi-conf.c

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <ccan/array_size/array_size.h>
2424
#include <ccan/endian/endian.h>
2525

26-
#include <systemd/sd-bus.h>
26+
#include <dbus/dbus.h>
2727

2828
#define MCTP_DBUS_NAME "xyz.openbmc_project.MCTP"
2929
#define MCTP_DBUS_PATH "/xyz/openbmc_project/mctp"
@@ -79,10 +79,11 @@ int find_port(nvme_mi_ep_t ep, uint8_t *portp, uint16_t *mtup)
7979
return found ? 0 : 1;
8080
}
8181

82-
int set_local_mtu(sd_bus *bus, unsigned int net, uint8_t eid, uint32_t mtu)
82+
int set_local_mtu(DBusConnection *bus, unsigned int net, uint8_t eid,
83+
uint32_t mtu)
8384
{
84-
sd_bus_error err = SD_BUS_ERROR_NULL;
85-
sd_bus_message *resp;
85+
DBusMessage *msg, *resp;
86+
DBusError berr;
8687
char *ep_path;
8788
int rc;
8889

@@ -99,26 +100,50 @@ int set_local_mtu(sd_bus *bus, unsigned int net, uint8_t eid, uint32_t mtu)
99100
*/
100101
mtu += 4;
101102

102-
rc = sd_bus_call_method(bus, MCTP_DBUS_NAME, ep_path,
103-
MCTP_DBUS_EP_IFACE, "SetMTU", &err, &resp,
104-
"u", mtu);
105-
if (rc < 0) {
106-
warnx("Failed to set local MTU: %s", strerror(-rc));
107-
return -1;
103+
rc = -1;
104+
dbus_error_init(&berr);
105+
msg = dbus_message_new_method_call(MCTP_DBUS_NAME, ep_path,
106+
MCTP_DBUS_EP_IFACE, "SetMTU");
107+
if (!msg) {
108+
warnx("Can't create D-Bus message");
109+
goto out;
108110
}
109111

110-
return 0;
112+
rc = dbus_message_append_args(msg,
113+
DBUS_TYPE_UINT32, &mtu,
114+
DBUS_TYPE_INVALID);
115+
if (!rc) {
116+
warnx("Can't construct D-Bus message arguments");
117+
goto out_free_msg;
118+
}
119+
120+
resp = dbus_connection_send_with_reply_and_block(bus, msg,
121+
2000, &berr);
122+
if (!resp) {
123+
warnx("Failed to set local MTU: %s (%s)", berr.message,
124+
berr.name);
125+
} else {
126+
dbus_message_unref(resp);
127+
rc = 0;
128+
}
129+
130+
out_free_msg:
131+
dbus_message_unref(msg);
132+
out:
133+
dbus_error_free(&berr);
134+
return rc;
111135
}
112136

113137
int main(int argc, char **argv)
114138
{
115139
uint16_t cur_mtu, mtu;
140+
DBusConnection *bus;
116141
const char *devstr;
117142
uint8_t eid, port;
118143
nvme_root_t root;
119144
unsigned int net;
120145
nvme_mi_ep_t ep;
121-
sd_bus *bus;
146+
DBusError berr;
122147
int rc;
123148

124149
if (argc != 2) {
@@ -141,10 +166,13 @@ int main(int argc, char **argv)
141166
goto out_free_root;
142167
}
143168

144-
rc = sd_bus_default_system(&bus);
145-
if (rc < 0) {
169+
dbus_error_init(&berr);
170+
bus = dbus_bus_get(DBUS_BUS_SYSTEM, &berr);
171+
if (!bus) {
172+
warnx("Failed opening D-Bus: %s (%s)\n",
173+
berr.message, berr.name);
174+
rc = -1;
146175
goto out_close_ep;
147-
warnx("Failed opening D-Bus: %s\n", strerror(-rc));
148176
}
149177

150178
rc = find_port(ep, &port, &mtu);
@@ -185,8 +213,9 @@ int main(int argc, char **argv)
185213
}
186214

187215
out_close_bus:
188-
sd_bus_close(bus);
216+
dbus_connection_unref(bus);
189217
out_close_ep:
218+
dbus_error_free(&berr);
190219
nvme_mi_close(ep);
191220
out_free_root:
192221
nvme_mi_free_root(root);

meson.build

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,9 @@ if openssl_dep.found()
8989
description: 'OpenSSL/LibreSSL API version @0@'.format(api_version))
9090
endif
9191

92-
# Check for libsystemd availability. Optional, only required for MCTP dbus scan
93-
libsystemd_dep = dependency('libsystemd', version: '>219', required: false)
94-
if libsystemd_dep.found()
95-
# When the user has CFLAGS=-static environment variable set
96-
# dependency() will find the shared library libsystemd Thus double
97-
# check if we are able to link
98-
if not cc.links('''#include <systemd/sd-bus.h>
99-
int main(void) {
100-
struct sd_bus *ret;
101-
return sd_bus_default(&ret);
102-
}
103-
''',
104-
dependencies: libsystemd_dep,
105-
name: 'libsystemd')
106-
libsystemd_dep = declare_dependency()
107-
endif
108-
conf.set('CONFIG_LIBSYSTEMD', libsystemd_dep.found(), description: 'Is libsystemd(>219) available?')
109-
endif
92+
# Check for libdus availability. Optional, only required for MCTP dbus scan
93+
libdbus_dep = dependency('dbus-1', required: false)
94+
conf.set('CONFIG_DBUS', libdbus_dep.found(), description: 'Enable dbus support?')
11095

11196
# local (cross-compilable) implementations of ccan configure steps
11297
conf.set10(

src/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ deps = [
3333
]
3434

3535
mi_deps = [
36-
libsystemd_dep,
36+
libdbus_dep,
3737
]
3838

3939
source_dir = meson.current_source_dir()

0 commit comments

Comments
 (0)