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 TETHERING_CGROUP_NETWORK STC_CGROUP_NETWORK "/TETHERING"
37 #define PROC_TASK_CHILDREN "/proc/%d/task/%d/children"
38 #define STC_CGROUP_NAME "stc"
39 #define STC_BACKGROUND_CGROUP_NAME "BACKGROUND"
40 #define STC_FOREGROUND_CGROUP_NAME "FOREGROUND"
41 #define STC_TETHERING_CGROUP_NAME "TETHERING"
44 * @desc Get one unsigned int32 value from cgroup
45 * @param cgroup_name - cgroup path
46 * @param file_name - cgroup content to write
47 * @param value - out parameter, value to fill
48 * @return negative value if error
50 int cgroup_read_node_uint32(const char *cgroup_name, const char *file_name,
54 * @desc Put unsigned int32 value to cgroup,
55 * @param cgroup_name - cgroup path
56 * @param file_name - cgroup content to write
57 * @param value - unsigned int32 data to write
58 * @return negative value if error
60 int cgroup_write_node_uint32(const char *cgroup_name, const char *file_name,
64 * @desc Put value to cgroup,
65 * @param cgroup_name - cgroup path
66 * @param file_name - cgroup content to write
67 * @param string -string to write
68 * @return negative value if error
70 int cgroup_write_node_str(const char *cgroup_name, const char *file_name,
75 * @param parentdir - parent cgroup path
76 * @param cgroup_name - cgroup subdirectory to write
77 * @param already - true if subdir already exists, NULL pointer is possible
78 * as formal argument, in this case it will not be filled
79 * @return negative value if error
81 int cgroup_make_subdir(const char *parentdir, const char *cgroup_name,
85 * @desc write pid into cgroup_subsystem/cgroup_name file,
86 * @param cgroup_subsystem path to /sys/fs/cgroup/subsystem
87 * @param cgroup_name - name in /sys/fs/cgroup/subsystem/
88 * @return negative value if error
90 stc_error_e cgroup_write_pid(const char *cgroup_subsystem,
91 const char *cgroup_name, const int pid);
93 stc_error_e cgroup_write_pid_fullpath(const char *cgroup_full_path,
97 * @desc doing the same as @see cgroup_write_pid,
98 * but also put into cgroup first level child processes
100 stc_error_e cgroup_write_pidtree(const char *cgroup_subsystem,
101 const char *cgroup_name, const int pid);
104 * @desc this function sets release agent path into cgroup subsystem
105 * and enables this mechanism
106 * @param cgroup_sussys - cgroup subsystem name, it's relative path to cgroup,
107 * relativelly default cgroup path (DEFAULT_CGROUP)
108 * @param release_agent full path to release agent executable
109 * @return negative value if error
111 int cgroup_set_release_agent(const char *cgroup_subsys,
112 const char *release_agent);
115 * @desc get PIDs of processes in a certain cgroup, an allocated array must be provided
116 * @return 0 if pids were read and array filled
118 int cgroup_get_pids(const char *name, GArray **pids);
121 * @desc initializes cgroups.
123 void cgroup_init(void);
125 #endif /*__STC_HELPER_CGROUP_H__*/