From c760231891489d845b936b30db4f66af1b6aab0d Mon Sep 17 00:00:00 2001 From: Suren Baghdasaryan Date: Sat, 2 Feb 2019 16:09:17 -0800 Subject: [PATCH] libprocessgroup: Fix file mode parsing that requires octal values JSON supports only decimal values and therefore file mode which should use octal values has to be represented as strings. Fix the implicit octal-to-decimal conversion and convert from string to octal in the code. Bug: 111307099 Test: confirmed by verifying correct file permissions Change-Id: I3ef9de0aea259f93bf74efeffca72d37d4740e15 Signed-off-by: Suren Baghdasaryan --- libprocessgroup/cgroup_map.cpp | 7 ++++--- rootdir/cgroups.json | 12 ++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/libprocessgroup/cgroup_map.cpp b/libprocessgroup/cgroup_map.cpp index 12cfb7e62..4fc085e32 100644 --- a/libprocessgroup/cgroup_map.cpp +++ b/libprocessgroup/cgroup_map.cpp @@ -128,7 +128,8 @@ static bool ReadDescriptors(std::map* descriptors std::string name = cgroups[i]["Controller"].asString(); descriptors->emplace(std::make_pair( name, - CgroupDescriptor(1, name, cgroups[i]["Path"].asString(), cgroups[i]["Mode"].asInt(), + CgroupDescriptor(1, name, cgroups[i]["Path"].asString(), + std::strtoul(cgroups[i]["Mode"].asString().c_str(), 0, 8), cgroups[i]["UID"].asString(), cgroups[i]["GID"].asString()))); } @@ -136,8 +137,8 @@ static bool ReadDescriptors(std::map* descriptors descriptors->emplace(std::make_pair( CGROUPV2_CONTROLLER_NAME, CgroupDescriptor(2, CGROUPV2_CONTROLLER_NAME, cgroups2["Path"].asString(), - cgroups2["Mode"].asInt(), cgroups2["UID"].asString(), - cgroups2["GID"].asString()))); + std::strtoul(cgroups2["Mode"].asString().c_str(), 0, 8), + cgroups2["UID"].asString(), cgroups2["GID"].asString()))); return true; } diff --git a/rootdir/cgroups.json b/rootdir/cgroups.json index 6eb88c957..aa7195609 100644 --- a/rootdir/cgroups.json +++ b/rootdir/cgroups.json @@ -3,40 +3,40 @@ { "Controller": "cpu", "Path": "/dev/cpuctl", - "Mode": 0755, + "Mode": "0755", "UID": "system", "GID": "system" }, { "Controller": "cpuacct", "Path": "/acct", - "Mode": 0555 + "Mode": "0555" }, { "Controller": "cpuset", "Path": "/dev/cpuset", - "Mode": 0755, + "Mode": "0755", "UID": "system", "GID": "system" }, { "Controller": "memory", "Path": "/dev/memcg", - "Mode": 0700, + "Mode": "0700", "UID": "root", "GID": "system" }, { "Controller": "schedtune", "Path": "/dev/stune", - "Mode": 0755, + "Mode": "0755", "UID": "system", "GID": "system" } ], "Cgroups2": { "Path": "/dev/cg2_bpf", - "Mode": 0600, + "Mode": "0600", "UID": "root", "GID": "root" }