Ignoring values of TOTAL_* details when fetching interface data.
[platform/core/connectivity/stc-manager.git] / src / helper / helper-cgroup.h
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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 /*
18  * Cgroup creation interface
19  */
20 #ifndef __STC_HELPER_CGROUP_H__
21 #define __STC_HELPER_CGROUP_H__
22
23 #include <errno.h>
24 #include <sys/stat.h>
25 #include <sys/mount.h>
26 #include <stdlib.h>
27
28 #include "stc-manager.h"
29 #include "helper-file.h"
30
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"
40
41 /**
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
47  */
48 int cgroup_read_node_uint32(const char *cgroup_name, const char *file_name,
49                             uint32_t *value);
50
51 /**
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
57  */
58 int cgroup_write_node_uint32(const char *cgroup_name, const char *file_name,
59                              uint32_t value);
60
61 /**
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
67  */
68 int cgroup_write_node_str(const char *cgroup_name, const char *file_name,
69                           const char *string);
70
71 /**
72  * @desc make cgroup,
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
78  */
79 int cgroup_make_subdir(const char *parentdir, const char *cgroup_name,
80                        bool *already);
81
82 /**
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
87  */
88 stc_error_e cgroup_write_pid(const char *cgroup_subsystem,
89                              const char *cgroup_name, const int pid);
90
91 stc_error_e cgroup_write_pid_fullpath(const char *cgroup_full_path,
92                                       const int pid);
93
94 /**
95  * @desc doing the same as @see cgroup_write_pid,
96  * but also put into cgroup first level child processes
97  */
98 stc_error_e cgroup_write_pidtree(const char *cgroup_subsystem,
99                                  const char *cgroup_name, const int pid);
100
101 /**
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
108  */
109 int cgroup_set_release_agent(const char *cgroup_subsys,
110                              const char *release_agent);
111
112 /**
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
115  */
116 int cgroup_get_pids(const char *name, GArray **pids);
117
118 /**
119  * @desc initializes cgroups.
120  */
121 void cgroup_init(void);
122
123 #endif /*__STC_HELPER_CGROUP_H__*/