2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * Cgroup creation interface
20 #ifndef __STC_HELPER_CGROUP_H__
21 #define __STC_HELPER_CGROUP_H__
25 #include <sys/mount.h>
28 #include "stc-manager.h"
29 #include "helper-file.h"
31 #define DEFAULT_CGROUP "/sys/fs/cgroup"
32 #define CGROUP_NETWORK DEFAULT_CGROUP "/net_cls"
33 #define STC_CGROUP_NETWORK CGROUP_NETWORK "/stc"
34 #define BACKGROUND_CGROUP_NETWORK STC_CGROUP_NETWORK "/BACKGROUND"
35 #define FOREGROUND_CGROUP_NETWORK STC_CGROUP_NETWORK "/FOREGROUND"
36 #define PROC_TASK_CHILDREN "/proc/%d/task/%d/children"
37 #define STC_CGROUP_NAME "stc"
38 #define STC_BACKGROUND_CGROUP_NAME "BACKGROUND"
39 #define STC_FOREGROUND_CGROUP_NAME "FOREGROUND"
42 * @desc Get one unsigned int32 value from cgroup
43 * @param cgroup_name - cgroup path
44 * @param file_name - cgroup content to write
45 * @param value - out parameter, value to fill
46 * @return negative value if error
48 int cgroup_read_node_uint32(const char *cgroup_name, const char *file_name,
52 * @desc Put unsigned int32 value to cgroup,
53 * @param cgroup_name - cgroup path
54 * @param file_name - cgroup content to write
55 * @param value - unsigned int32 data to write
56 * @return negative value if error
58 int cgroup_write_node_uint32(const char *cgroup_name, const char *file_name,
62 * @desc Put value to cgroup,
63 * @param cgroup_name - cgroup path
64 * @param file_name - cgroup content to write
65 * @param string -string to write
66 * @return negative value if error
68 int cgroup_write_node_str(const char *cgroup_name, const char *file_name,
73 * @param parentdir - parent cgroup path
74 * @param cgroup_name - cgroup subdirectory to write
75 * @param already - true if subdir already exists, NULL pointer is possible
76 * as formal argument, in this case it will not be filled
77 * @return negative value if error
79 int cgroup_make_subdir(const char *parentdir, const char *cgroup_name,
83 * @desc write pid into cgroup_subsystem/cgroup_name file,
84 * @param cgroup_subsystem path to /sys/fs/cgroup/subsystem
85 * @param cgroup_name - name in /sys/fs/cgroup/subsystem/
86 * @return negative value if error
88 stc_error_e cgroup_write_pid(const char *cgroup_subsystem,
89 const char *cgroup_name, const int pid);
91 stc_error_e cgroup_write_pid_fullpath(const char *cgroup_full_path,
95 * @desc doing the same as @see cgroup_write_pid,
96 * but also put into cgroup first level child processes
98 stc_error_e cgroup_write_pidtree(const char *cgroup_subsystem,
99 const char *cgroup_name, const int pid);
102 * @desc this function sets release agent path into cgroup subsystem
103 * and enables this mechanism
104 * @param cgroup_sussys - cgroup subsystem name, it's relative path to cgroup,
105 * relativelly default cgroup path (DEFAULT_CGROUP)
106 * @param release_agent full path to release agent executable
107 * @return negative value if error
109 int cgroup_set_release_agent(const char *cgroup_subsys,
110 const char *release_agent);
113 * @desc get PIDs of processes in a certain cgroup, an allocated array must be provided
114 * @return 0 if pids were read and array filled
116 int cgroup_get_pids(const char *name, GArray **pids);
119 * @desc initializes cgroups.
121 void cgroup_init(void);
123 #endif /*__STC_HELPER_CGROUP_H__*/