xref: /aosp_15_r20/system/core/libprocessgroup/util/cgroup_controller.cpp (revision 00c7fec1bb09f3284aad6a6f96d2f63dfc3650ad)
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <processgroup/cgroup_controller.h>
18 
19 #include <cstring>
20 
CgroupController(uint32_t version,uint32_t flags,const std::string & name,const std::string & path,uint32_t max_activation_depth)21 CgroupController::CgroupController(uint32_t version, uint32_t flags, const std::string& name,
22                                    const std::string& path, uint32_t max_activation_depth)
23     : version_(version), flags_(flags), max_activation_depth_(max_activation_depth) {
24     // strlcpy isn't available on host. Although there is an implementation
25     // in licutils, libcutils itself depends on libcgrouprc_format, causing
26     // a circular dependency.
27     strncpy(name_, name.c_str(), sizeof(name_) - 1);
28     name_[sizeof(name_) - 1] = '\0';
29     strncpy(path_, path.c_str(), sizeof(path_) - 1);
30     path_[sizeof(path_) - 1] = '\0';
31 }
32 
version() const33 uint32_t CgroupController::version() const {
34     return version_;
35 }
36 
flags() const37 uint32_t CgroupController::flags() const {
38     return flags_;
39 }
40 
max_activation_depth() const41 uint32_t CgroupController::max_activation_depth() const {
42     return max_activation_depth_;
43 }
44 
name() const45 const char* CgroupController::name() const {
46     return name_;
47 }
48 
path() const49 const char* CgroupController::path() const {
50     return path_;
51 }
52 
set_flags(uint32_t flags)53 void CgroupController::set_flags(uint32_t flags) {
54     flags_ = flags;
55 }