Commit d8bbda91 authored by Lennart Poettering's avatar Lennart Poettering
Browse files

cgroup: expose cgroup attributes as unit properties on the bus

parent 14e639ae
......@@ -330,6 +330,40 @@ int bus_unit_append_cgroups(DBusMessageIter *i, const char *property, void *data
return 0;
}
int bus_unit_append_cgroup_attrs(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
CGroupAttribute *a;
DBusMessageIter sub, sub2;
if (!dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "(sss)", &sub))
return -ENOMEM;
LIST_FOREACH(by_unit, a, u->meta.cgroup_attributes) {
char *v = NULL;
bool success;
if (a->map_callback)
a->map_callback(a->controller, a->name, a->value, &v);
success =
dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2) &&
dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &a->controller) &&
dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &a->name) &&
dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, v ? &v : &a->value) &&
dbus_message_iter_close_container(&sub, &sub2);
free(v);
if (!success)
return -ENOMEM;
}
if (!dbus_message_iter_close_container(i, &sub))
return -ENOMEM;
return 0;
}
int bus_unit_append_need_daemon_reload(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
dbus_bool_t b;
......
......@@ -109,6 +109,7 @@
" <property name=\"IgnoreOnSnapshot\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"DefaultControlGroup\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"ControlGroup\" type=\"as\" access=\"read\"/>\n" \
" <property name=\"ControlGroupAttributes\" type=\"a(sss)\" access=\"read\"/>\n" \
" <property name=\"NeedDaemonReload\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"JobTimeoutUSec\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"ConditionTimestamp\" type=\"t\" access=\"read\"/>\n" \
......@@ -169,6 +170,7 @@
{ "org.freedesktop.systemd1.Unit", "IgnoreOnSnapshot", bus_property_append_bool, "b", &u->meta.ignore_on_snapshot }, \
{ "org.freedesktop.systemd1.Unit", "DefaultControlGroup", bus_unit_append_default_cgroup, "s", u }, \
{ "org.freedesktop.systemd1.Unit", "ControlGroup", bus_unit_append_cgroups, "as", u }, \
{ "org.freedesktop.systemd1.Unit", "ControlGroupAttributes", bus_unit_append_cgroup_attrs, "a(sss)", u }, \
{ "org.freedesktop.systemd1.Unit", "NeedDaemonReload", bus_unit_append_need_daemon_reload, "b", u }, \
{ "org.freedesktop.systemd1.Unit", "JobTimeoutUSec", bus_property_append_usec, "t", &u->meta.job_timeout }, \
{ "org.freedesktop.systemd1.Unit", "ConditionTimestamp", bus_property_append_usec, "t", &u->meta.condition_timestamp.realtime }, \
......@@ -191,6 +193,7 @@ int bus_unit_append_can_isolate(DBusMessageIter *i, const char *property, void *
int bus_unit_append_job(DBusMessageIter *i, const char *property, void *data);
int bus_unit_append_default_cgroup(DBusMessageIter *i, const char *property, void *data);
int bus_unit_append_cgroups(DBusMessageIter *i, const char *property, void *data);
int bus_unit_append_cgroup_attrs(DBusMessageIter *i, const char *property, void *data);
int bus_unit_append_need_daemon_reload(DBusMessageIter *i, const char *property, void *data);
int bus_unit_append_load_error(DBusMessageIter *i, const char *property, void *data);
......
......@@ -2546,6 +2546,30 @@ static int print_property(const char *name, DBusMessageIter *iter) {
return 0;
} else if (dbus_message_iter_get_element_type(iter) == DBUS_TYPE_STRUCT && streq(name, "ControlGroupAttributes")) {
DBusMessageIter sub, sub2;
dbus_message_iter_recurse(iter, &sub);
while (dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_STRUCT) {
const char *controller, *attr, *value;
dbus_message_iter_recurse(&sub, &sub2);
if (bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &controller, true) >= 0 &&
bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &attr, true) >= 0 &&
bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &value, false) >= 0) {
printf("ControlGroupAttribute={ controller=%s ; attribute=%s ; value=\"%s\" }\n",
controller,
attr,
value);
}
dbus_message_iter_next(&sub);
}
return 0;
} else if (dbus_message_iter_get_element_type(iter) == DBUS_TYPE_STRUCT && startswith(name, "Exec")) {
DBusMessageIter sub;
......
......@@ -686,9 +686,17 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) {
fprintf(f, "%s\tControlGroup: %s:%s\n",
prefix, b->controller, b->path);
LIST_FOREACH(by_unit, a, u->meta.cgroup_attributes)
LIST_FOREACH(by_unit, a, u->meta.cgroup_attributes) {
char *v = NULL;
if (a->map_callback)
a->map_callback(a->controller, a->name, a->value, &v);
fprintf(f, "%s\tControlGroupAttribute: %s %s \"%s\"\n",
prefix, a->controller, a->name, a->value);
prefix, a->controller, a->name, v ? v : a->value);
free(v);
}
if (UNIT_VTABLE(u)->dump)
UNIT_VTABLE(u)->dump(u, f, prefix2);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment