1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2011 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include "cgroup-attr.h"
23 #include "cgroup-util.h"
27 int cgroup_attribute_apply(CGroupAttribute *a, CGroupBonding *b) {
28 _cleanup_free_ char *path = NULL, *v = NULL;
33 b = cgroup_bonding_find_list(b, a->controller);
37 if (a->semantics && a->semantics->map_write) {
38 r = a->semantics->map_write(a->semantics, a->value, &v);
43 r = cg_get_path(a->controller, b->path, a->name, &path);
47 r = write_string_file(path, v ? v : a->value);
49 log_warning("Failed to write '%s' to %s: %s", v ? v : a->value, path, strerror(-r));
54 int cgroup_attribute_apply_list(CGroupAttribute *first, CGroupBonding *b) {
58 LIST_FOREACH(by_unit, a, first) {
61 k = cgroup_attribute_apply(a, b);
69 bool cgroup_attribute_matches(CGroupAttribute *a, const char *controller, const char *name) {
73 if (streq(a->controller, controller) && (!name || streq(a->name, name)))
78 else if (streq(a->name, name)) {
80 x = strlen(a->controller);
84 memcmp(a->controller, name, x) == 0 &&
92 CGroupAttribute *cgroup_attribute_find_list(
93 CGroupAttribute *first,
94 const char *controller,
100 LIST_FOREACH(by_unit, a, first)
101 if (cgroup_attribute_matches(a, controller, name))
107 void cgroup_attribute_free(CGroupAttribute *a) {
111 LIST_REMOVE(CGroupAttribute, by_unit, a->unit->cgroup_attributes, a);
119 void cgroup_attribute_free_list(CGroupAttribute *first) {
120 CGroupAttribute *a, *n;
122 LIST_FOREACH_SAFE(by_unit, a, n, first)
123 cgroup_attribute_free(a);
126 void cgroup_attribute_free_some(CGroupAttribute *first, const char *controller, const char *name) {
127 CGroupAttribute *a, *n;
129 LIST_FOREACH_SAFE(by_unit, a, n, first)
130 if (cgroup_attribute_matches(a, controller, name))
131 cgroup_attribute_free(a);