[prev in list] [next in list] [prev in thread] [next in thread]
List: systemd-devel
Subject: [systemd-devel] [PATCH] device cgroup: don't create a new CGroupDeviceAllow when it already in the l
From: gaofeng () cn ! fujitsu ! com (Gao feng)
Date: 2013-08-26 7:30:49
Message-ID: 1377502249-9764-1-git-send-email-gaofeng () cn ! fujitsu ! com
[Download RAW message or body]
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.
---
src/core/dbus-cgroup.c | 32 +++++++++++++++++++++++---------
1 file changed, 23 insertions(+), 9 deletions(-)
diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c
index 9e97b20..30c99dd 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 (!strcmp(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++;
--
1.8.3.1
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic