diff options
author | Lennart Poettering <lennart@poettering.net> | 2011-08-20 00:42:50 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2011-08-21 20:07:08 +0200 |
commit | d8bbda9141f03c3a2877639e7d43b5f35767840f (patch) | |
tree | 726e20e8deaeed328a7586eeb42d4b81957cd869 | |
parent | 14e639ae7a1dbf156273ce697d30fbc6c6594209 (diff) | |
download | systemd-d8bbda9141f03c3a2877639e7d43b5f35767840f.tar.gz |
cgroup: expose cgroup attributes as unit properties on the bus
-rw-r--r-- | src/dbus-unit.c | 34 | ||||
-rw-r--r-- | src/dbus-unit.h | 3 | ||||
-rw-r--r-- | src/systemctl.c | 24 | ||||
-rw-r--r-- | src/unit.c | 12 |
4 files changed, 71 insertions, 2 deletions
diff --git a/src/dbus-unit.c b/src/dbus-unit.c index b110e33174..611a1202f4 100644 --- a/src/dbus-unit.c +++ b/src/dbus-unit.c @@ -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; diff --git a/src/dbus-unit.h b/src/dbus-unit.h index b5c3010728..9fed6d731d 100644 --- a/src/dbus-unit.h +++ b/src/dbus-unit.h @@ -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); diff --git a/src/systemctl.c b/src/systemctl.c index bb998d37e2..604400d8fb 100644 --- a/src/systemctl.c +++ b/src/systemctl.c @@ -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; diff --git a/src/unit.c b/src/unit.c index 5006742d9d..e0f4a1bb31 100644 --- a/src/unit.c +++ b/src/unit.c @@ -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); |