Need help on Dbus API's

N, Soumya P soumya.p.n at
Mon Mar 28 06:40:58 UTC 2016


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)

We found below references:

We downloaded system-221 package, compiled and ran some sample programs.
We tried few API's like GetUnit(), StartUnit() seems to be working. Then we tried below API to set property on a cgroup which did not succeed:
SetUnitProperties(in s name, in  b runtime,  a(sv) properties);

We used below .slice unit file and tried below program:

Sample.slice (created in /etc/system/system):
Description=Gold Cg Slice



Then we started this using:
# systemctl daemon-reload
# systemctl start sample.slice


#include <stdio.h>
#include <stdlib.h>
#include <systemd/sd-bus.h>

int main(int argc, char *argv[]) {
        sd_bus_error error = SD_BUS_ERROR_NULL;
        sd_bus_message *reply = NULL;
        const char *path = NULL;
        const char *p = NULL;
        sd_bus *bus = NULL;
        int r;

        /* Connect to the system bus */

        r = sd_bus_call_method(bus,
                        "GetUnit", &error,
                        "s", "sample.slice");

         if(r < 0) {
                fprintf(stderr, "Failed to issue method call: %s\n", error.message);

        r = sd_bus_message_read(reply, "s", &p);

        if(r < 0)
        fprintf(stderr, "Failed to parse response message: %s\n", strerror(-r));
        printf("sd bus message read = %s \n", p);

        r = sd_bus_call_method(bus,
                        "SetUnitProperties", &error,
                        &reply, "s", "sample.slice",0, ("BlockIOWeight", 500));

//SetUnitProperties("sample.slice",0, ("BlockIOWeight", 500) );

        if(r < 0)
        fprintf(stderr, "SetUnitProperties() failed: %s \n", error.message);
        printf("SetUnitPropreties suceeded \n");

Ran this program and seeing below error:

Failed to parse response message: No such device or address
SetUnitProperties() failed: (null)

Looking at this error seems like ENXIO is the error and we saw in the sources that this error is returned in case of sd_bus_message_read() in several places.
Looking at the failure of SetUnitProperties() API, we are not sure about the usage of these API's. We even tried calling the API SetUnitProperties() directly but got "undefined reference" error.

As we are beginners of systemd programming it will help if there is any material related to sdbus programming.
Could you please help us?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the dbus mailing list