Debug a call to method ssa(sv)a(sa(sv)) from libdbus

Felip Moll lipixx at gmail.com
Fri Mar 11 13:56:04 UTC 2022


Thanks for all the replies, these have inspired me and I got the signature
correctly set.
I past the code just as a reference, for the a(sv) part with v being an
array of uint32, 'au'.

It is still not working but at least I got the message well formed.. it
seems. Now I get: "Process org.freedesktop.systemd1 exited with status 1"
as a reply but I cannot see anything in 'dbus-monitor --system', so I guess
the message is still not being sent?

For newbies like me trying to debug this, it is helpful to add some debug
just printing the signature of the message while you are creating with
dbus_message_get_signature(msg). You can use also
dbus_message_iter_get_signature for the iterators. Also I used
dbus/tools/dbus-print-message.h functions to print my message internals.

]# ./main 12568
-- Starting query --
Calling remote method with 12568
SIGNATURE IS0: ss
SIGNATURE IS1: ssa(sv)
SIGNATURE IS2: ssa(sv)a(sa(sv))
method call sender=(null sender) -> destination=org.freedesktop.systemd1
serial=0 path=/org/freedesktop/systemd1;
interface=org.freedesktop.systemd1.Manager; member=StartTransientUnit
   string "my_test.scope"
   string "fail"
   array [
      struct {
         string "PIDs"
         variant             array [
               uint32 12568
            ]
      }
   ]
   array [
   ]
Request Sent... blocking for reply.

-- Reply received --
output says: Process org.freedesktop.systemd1 exited with status 1

Below how I formed the 'a(sv)' with v being 'au' (note, no error control!):
---
static dbus_bool_t _dbus_asv_add_fixed_array(DBusMessageIter *arr_iter,
    const char *key, char element_type,
    const void *value, int n_elements)
{
/* Signature for the container v - 'array of <uint32>' */
char sigy[] = { DBUS_TYPE_ARRAY, element_type, '\0' };
char sigx[5];
DBusMessageIter it1, it2, it3, it4;

/* Signature for the container - (sv) part */
sigx[0] = DBUS_STRUCT_BEGIN_CHAR;
sigx[1] = DBUS_TYPE_STRING;
sigx[2] = DBUS_TYPE_VARIANT;
sigx[3] = DBUS_STRUCT_END_CHAR;
sigx[4] = '\0';

dbus_message_iter_open_container(arr_iter, DBUS_TYPE_ARRAY, sigx, &it1); /*
Open array*/
dbus_message_iter_open_container(&it1, DBUS_TYPE_STRUCT, NULL, &it2); /*
Open struct */
dbus_message_iter_append_basic(&it2, DBUS_TYPE_STRING, &key); /* Insert
string */
dbus_message_iter_open_container(&it2, DBUS_TYPE_VARIANT, sigy, &it3); /*
Open variant */
dbus_message_iter_open_container(&it3, DBUS_TYPE_ARRAY, (sigy + 1), &it4);
/* Open array */
dbus_message_iter_append_fixed_array(&it4, element_type , &value,
n_elements); /* Insert elements */
dbus_message_iter_close_container(&it3, &it4); /* Close array */
dbus_message_iter_close_container(&it2, &it3); /* Close variant */
dbus_message_iter_close_container(&it1, &it2); /* Close struct */
dbus_message_iter_close_container(arr_iter, &it1); /* Close array */

return true;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/dbus/attachments/20220311/7fdf1434/attachment.htm>


More information about the dbus mailing list