mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-25 23:21:33 +03:00
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
This commit is contained in:
parent
e862b60f1c
commit
ad7bfffde5
@ -314,21 +314,35 @@ int bus_cgroup_set_property(
|
||||
}
|
||||
|
||||
if (mode != UNIT_CHECK) {
|
||||
a = new0(CGroupDeviceAllow, 1);
|
||||
if (!a)
|
||||
return -ENOMEM;
|
||||
CGroupDeviceAllow *b;
|
||||
bool exist = false;
|
||||
|
||||
a->path = strdup(path);
|
||||
if (!a->path) {
|
||||
free(a);
|
||||
return -ENOMEM;
|
||||
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++;
|
||||
|
Loading…
Reference in New Issue
Block a user