Debug a call to method ssa(sv)a(sa(sv)) from libdbus
Felip Moll
lipixx at gmail.com
Thu Mar 10 18:50:10 UTC 2022
Hi,
I am playing with libdbus and want to call a specific method with this
signature:
'ssa(sv)a(sa(sv))'.
Specifically this method is StartTransientUnit from systemd1.manager.
I want to do it with libdbus, not sd-dbus. I think I filled in the
arguments of the message but when I call it I cannot see anything in
'dbus-monitor --system'.
My code seems to end with no error, except that when I check for the reply
it says:
"Connection was disconnected before a reply was received".
I am looking for some guidance on what I am doing wrong, and specifically
how to debug my message composition.
Am I filling up the message correctly? I got inspired from
dbus-asv-util.[c|h] for _dbus_asv_add_fixed_array call.
Here is the sequence of operations, but not the real code.
For the real code please check https://pastebin.com/raw/Ev73xzMJ
printf("Calling remote method with %d\n", param);
dbus_error_init(&err);
conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
ret = dbus_bus_request_name(conn, "my.test.caller",
DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
msg = dbus_message_new_method_call("org.freedesktop.systemd1",
"/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager",
"StartTransientUnit");
dbus_message_iter_init_append(msg, &args_itr);
dbus_message_iter_append_basic(&args_itr, DBUS_TYPE_STRING, &name);
dbus_message_iter_append_basic(&args_itr, DBUS_TYPE_STRING, &mode);
_dbus_asv_add_fixed_array(&args_itr, pid_str, DBUS_TYPE_UINT32, &pids,
npids);
dbus_message_iter_open_container(&args_itr, DBUS_TYPE_ARRAY,
DBUS_TYPE_UINT32_AS_STRING, &cont_itr);
dbus_message_iter_append_basic(&cont_itr, DBUS_TYPE_UINT32, &zero);
dbus_message_iter_close_container(&args_itr, &cont_itr);
dbus_connection_send_with_reply(conn, msg, &pending, -1);
dbus_connection_flush(conn);
printf("Request Sent... blocking for reply.\n");
dbus_message_unref(msg);
dbus_pending_call_block(pending);
msg = dbus_pending_call_steal_reply(pending);
printf("\n-- Reply received --\n");
dbus_pending_call_unref(pending);
dbus_message_iter_init(msg, &args_itr);
dbus_message_iter_get_basic(&args_itr, &rcstr);
printf("Test: ret. arg is type string: %s\n", rcstr);
dbus_message_unref(msg);
Thanks and note this is a test code.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/dbus/attachments/20220310/583c7dbd/attachment.htm>
More information about the dbus
mailing list