summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGao feng <gaofeng@cn.fujitsu.com>2013-08-28 09:49:11 +0800
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-08-28 08:04:56 -0400
commitad7bfffde594bf141e13f17e8d8214bfa29ea635 (patch)
treea50a600f80a9853b3880878e2fd73cb56caf1bb1 /src
parente862b60f1c77bc12bf49475930f79ce68489828a (diff)
device cgroup: don't create a new CGroupDeviceAllow when it already in the list
If a device node is already in the device_allow list of CGroupContext, we should replace it instead of create a new one and append this new one to the end of device_allow list. change from v1: use streq to replace !strcmp
Diffstat (limited to 'src')
-rw-r--r--src/core/dbus-cgroup.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c
index 9e97b20d1e..4ce7dc5e7f 100644
--- a/src/core/dbus-cgroup.c
+++ b/src/core/dbus-cgroup.c
@@ -314,21 +314,35 @@ int bus_cgroup_set_property(
}
if (mode != UNIT_CHECK) {
- a = new0(CGroupDeviceAllow, 1);
- if (!a)
- return -ENOMEM;
-
- a->path = strdup(path);
- if (!a->path) {
- free(a);
- return -ENOMEM;
+ CGroupDeviceAllow *b;
+ bool exist = false;
+
+ LIST_FOREACH(device_allow, b, c->device_allow) {
+ if (streq(b->path, path)) {
+ a = b;
+ exist = true;
+ break;
+ }
+ }
+
+ if (!exist) {
+ a = new0(CGroupDeviceAllow, 1);
+ if (!a)
+ return -ENOMEM;
+
+ a->path = strdup(path);
+ if (!a->path) {
+ free(a);
+ return -ENOMEM;
+ }
}
a->r = !!strchr(rwm, 'r');
a->w = !!strchr(rwm, 'w');
a->m = !!strchr(rwm, 'm');
- LIST_PREPEND(CGroupDeviceAllow, device_allow, c->device_allow, a);
+ if (!exist)
+ LIST_PREPEND(CGroupDeviceAllow, device_allow, c->device_allow, a);
}
n++;