xref: /aosp_15_r20/system/core/libprocessgroup/util/cgroup_descriptor.cpp (revision 00c7fec1bb09f3284aad6a6f96d2f63dfc3650ad)
1 /*
2  * Copyright (C) 2024 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_descriptor.h>
18 
19 #include <processgroup/util.h>  // For flag values
20 
CgroupDescriptor(uint32_t version,const std::string & name,const std::string & path,mode_t mode,const std::string & uid,const std::string & gid,uint32_t flags,uint32_t max_activation_depth)21 CgroupDescriptor::CgroupDescriptor(uint32_t version, const std::string& name,
22                                    const std::string& path, mode_t mode, const std::string& uid,
23                                    const std::string& gid, uint32_t flags,
24                                    uint32_t max_activation_depth)
25     : controller_(version, flags, name, path, max_activation_depth),
26       mode_(mode),
27       uid_(uid),
28       gid_(gid) {}
29 
set_mounted(bool mounted)30 void CgroupDescriptor::set_mounted(bool mounted) {
31     uint32_t flags = controller_.flags();
32     if (mounted) {
33         flags |= CGROUPRC_CONTROLLER_FLAG_MOUNTED;
34     } else {
35         flags &= ~CGROUPRC_CONTROLLER_FLAG_MOUNTED;
36     }
37     controller_.set_flags(flags);
38 }
39