Need help on Dbus API's
Lennart Poettering
mzqohf at 0pointer.de
Fri Apr 1 18:13:06 UTC 2016
On Mon, 28.03.16 06:40, N, Soumya P (soumya.p.n at hpe.com) wrote:
> Hello,
>
> We have a requirement to get/set some properties on /sys/fs/cgroup/blkio and also child cgroups under this (ex: /sys/fs/cgroup/blkio/Gold_cg).
> We found that libcgroups are going to be obsoleted from RHEL 7 onwards and hence we started with systemd cgroups and we found that we need to use sdbus API's.
> (We have RHEL 7.2 installed on our system)
You sent your message to the dbus mailing list, which is only for
issues in the dbus protocol and the dbus reference
implementation. However, you are using the sd-bus implementation and
systemd as service, hence systemd-devel would be the right place to
discuss this.
>
> r = sd_bus_call_method(bus,
> "org/freedesktop/systemd1",
> "/org/freedesktop/systemd1",
> "org.freedesktop.systemd1.Manager",
> "SetUnitProperties", &error,
> &reply, "s", "sample.slice",0,
> ("BlockIOWeight", 500));
Please read up on the sd_bus_message_append(3) man page. You need to
specify the full signature string for SetUnitProperties() instead of
just "s". (i.e. the right signature argument is "sba(sv)"). Then you
need to follow with the matching arguments.
Something like this should work (untested):
r = sd_bus_call_method(bus,
"org/freedesktop/systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"SetUnitProperties", &error,
&reply,
"sba(sv)",
"sample.slice", /* this is the unit name string */
0, /* this is the "runtime" bool */
1, /* number of array entries */
"BlockIOWeight", /* Property name */
"t", /* Property variant type */
UINT64_C(500)); /* Property value */
Basically, the parameters you specifiy in the signature strings must
follow the signature string immediately. For arrays, you need to
specify the number of entries following first, and for variants you
need to specify the type of the variant first.
It's important to use the UINT64_C() macro for the 500 argument, since
this is a varargs function, and if you don't fix the type, then C will
push this onto the stack as the smallest type that is at least "int",
and that's int32_t. However, as we specify "t" as variant type (which
is a unsigned 64bit type), we need to make sure C gets that right, and
explicitly request a 64bit unsigned constant to be put on the stack,
hence the UINT64_C() macro...
Lennart
--
Lennart Poettering, Red Hat
More information about the dbus
mailing list