dbus-cgroup.c revision 7041efe9600e569da6089c36d00fa3ff58e33178
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "path-util.h"
#include "dbus-cgroup.h"
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_cgroup_append_device_policy, cgroup_device_policy, CGroupDevicePolicy);
CGroupContext *c = data;
assert(i);
assert(c);
return -ENOMEM;
return -ENOMEM;
}
if (!dbus_message_iter_close_container(i, &sub))
return -ENOMEM;
return 0;
}
static int bus_cgroup_append_device_bandwidths(DBusMessageIter *i, const char *property, void *data) {
CGroupContext *c = data;
assert(i);
assert(c);
return -ENOMEM;
continue;
return -ENOMEM;
}
if (!dbus_message_iter_close_container(i, &sub))
return -ENOMEM;
return 0;
}
CGroupContext *c = data;
assert(i);
assert(c);
return -ENOMEM;
const char *rwm;
char buf[4];
unsigned k = 0;
if (a->r)
buf[k++] = 'r';
if (a->w)
buf[k++] = 'w';
if (a->m)
buf[k++] = 'm';
buf[k] = 0;
return -ENOMEM;
}
if (!dbus_message_iter_close_container(i, &sub))
return -ENOMEM;
return 0;
}
const BusProperty bus_cgroup_context_properties[] = {
{ "BlockIOAccounting", bus_property_append_bool, "b", offsetof(CGroupContext, blockio_accounting) },
{}
};
Unit *u,
CGroupContext *c,
const char *name,
DBusMessageIter *i,
assert(u);
assert(c);
assert(i);
if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_BOOLEAN)
return -EINVAL;
if (mode != UNIT_CHECK) {
dbus_bool_t b;
dbus_message_iter_get_basic(i, &b);
c->cpu_accounting = b;
unit_write_drop_in_private_section(u, mode, "cpu-accounting", b ? "CPUAccounting=yes" : "CPUAccounting=no");
}
return 1;
unsigned long ul;
if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_UINT64)
return -EINVAL;
return -EINVAL;
if (mode != UNIT_CHECK) {
c->cpu_shares = ul;
}
return 1;
if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_BOOLEAN)
return -EINVAL;
if (mode != UNIT_CHECK) {
dbus_bool_t b;
dbus_message_iter_get_basic(i, &b);
c->blockio_accounting = b;
unit_write_drop_in_private_section(u, mode, "block-io-accounting", b ? "BlockIOAccounting=yes" : "BlockIOAccounting=no");
}
return 1;
unsigned long ul;
if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_UINT64)
return -EINVAL;
return -EINVAL;
if (mode != UNIT_CHECK) {
c->cpu_shares = ul;
}
return 1;
if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_BOOLEAN)
return -EINVAL;
if (mode != UNIT_CHECK) {
dbus_bool_t b;
dbus_message_iter_get_basic(i, &b);
c->memory_accounting = b;
unit_write_drop_in_private_section(u, mode, "memory-accounting", b ? "MemoryAccounting=yes" : "MemoryAccounting=no");
}
return 1;
if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_UINT64)
return -EINVAL;
if (mode != UNIT_CHECK) {
c->memory_limit = limit;
} else {
c->memory_soft_limit = limit;
}
}
return 1;
const char *policy;
if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_STRING)
return -EINVAL;
if (p < 0)
return -EINVAL;
if (mode != UNIT_CHECK) {
char *buf;
c->device_policy = p;
}
return 1;
unsigned n = 0;
if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_ARRAY ||
return -EINVAL;
dbus_message_iter_recurse(i, &sub);
return -EINVAL;
return -EINVAL;
}
rwm = "rwm";
return -EINVAL;
}
n++;
if (mode != UNIT_CHECK) {
if (!a)
return -ENOMEM;
if (!a->path) {
free(a);
return -ENOMEM;
}
}
}
if (mode != UNIT_CHECK) {
if (n == 0) {
while (c->device_allow)
}
if (!f)
return -ENOMEM;
fputs("DeviceAllow=\n", f);
fflush(f);
}
return 1;
}
return 0;
}