]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: introduce cgroup_add_device_allow()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 6 Aug 2018 04:42:14 +0000 (13:42 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 6 Aug 2018 04:42:14 +0000 (13:42 +0900)
src/core/cgroup.c
src/core/cgroup.h
src/core/load-fragment.c

index eea30b21ff5999b9c04c3dbd39480fbe3a6cdff0..0ea1b540400b979ca1840de9914937fd469cfadb 100644 (file)
@@ -304,6 +304,35 @@ void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix) {
         }
 }
 
+int cgroup_add_device_allow(CGroupContext *c, const char *dev, const char *mode) {
+        _cleanup_free_ CGroupDeviceAllow *a = NULL;
+        _cleanup_free_ char *d = NULL;
+
+        assert(c);
+        assert(dev);
+        assert(isempty(mode) || in_charset(mode, "rwm"));
+
+        a = new(CGroupDeviceAllow, 1);
+        if (!a)
+                return -ENOMEM;
+
+        d = strdup(dev);
+        if (!d)
+                return -ENOMEM;
+
+        *a = (CGroupDeviceAllow) {
+                .path = TAKE_PTR(d),
+                .r = isempty(mode) || !!strchr(mode, 'r'),
+                .w = isempty(mode) || !!strchr(mode, 'w'),
+                .m = isempty(mode) || !!strchr(mode, 'm'),
+        };
+
+        LIST_PREPEND(device_allow, c->device_allow, a);
+        TAKE_PTR(a);
+
+        return 0;
+}
+
 static int lookup_block_device(const char *p, dev_t *ret) {
         struct stat st;
         int r;
index bda139c30bca8e8e80dbd4a2f2782b5e67944bb1..2ce87f3b9935aa1e5cd9e6108e176054af51fefa 100644 (file)
@@ -137,6 +137,8 @@ void cgroup_context_free_io_device_limit(CGroupContext *c, CGroupIODeviceLimit *
 void cgroup_context_free_blockio_device_weight(CGroupContext *c, CGroupBlockIODeviceWeight *w);
 void cgroup_context_free_blockio_device_bandwidth(CGroupContext *c, CGroupBlockIODeviceBandwidth *b);
 
+int cgroup_add_device_allow(CGroupContext *c, const char *dev, const char *mode);
+
 CGroupMask unit_get_own_mask(Unit *u);
 CGroupMask unit_get_delegate_mask(Unit *u);
 CGroupMask unit_get_members_mask(Unit *u);
index 908d16c9f26e1c7bfb7498b55bffc39f18fe90e5..07fcbaacc0f54214ece9e5532022e0cda60f2522 100644 (file)
@@ -3212,7 +3212,6 @@ int config_parse_device_allow(
 
         _cleanup_free_ char *path = NULL, *resolved = NULL;
         CGroupContext *c = data;
-        CGroupDeviceAllow *a;
         const char *p = rvalue;
         int r;
 
@@ -3261,17 +3260,7 @@ int config_parse_device_allow(
                 return 0;
         }
 
-        a = new0(CGroupDeviceAllow, 1);
-        if (!a)
-                return log_oom();
-
-        a->path = TAKE_PTR(resolved);
-        a->r = isempty(p) || !!strchr(p, 'r');
-        a->w = isempty(p) || !!strchr(p, 'w');
-        a->m = isempty(p) || !!strchr(p, 'm');
-
-        LIST_PREPEND(device_allow, c->device_allow, a);
-        return 0;
+        return cgroup_add_device_allow(c, resolved, p);
 }
 
 int config_parse_io_device_weight(