Fixed some svace issues
[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 PROC_TASK_CHILDREN   "/proc/%d/task/%d/children"
34
35 /**
36  * @desc Get one unsigned int32 value from cgroup
37  * @param cgroup_name - cgroup path
38  * @param file_name - cgroup content to write
39  * @param value - out parameter, value to fill
40  * @return negative value if error
41  */
42 int cgroup_read_node_uint32(const char *cgroup_name, const char *file_name,
43                             uint32_t *value);
44
45 /**
46  * @desc Put unsigned int32 value to cgroup,
47  * @param cgroup_name - cgroup path
48  * @param file_name - cgroup content to write
49  * @param value - unsigned int32 data to write
50  * @return negative value if error
51  */
52 int cgroup_write_node_uint32(const char *cgroup_name, const char *file_name,
53                              uint32_t value);
54
55 /**
56  * @desc Put value to cgroup,
57  * @param cgroup_name - cgroup path
58  * @param file_name - cgroup content to write
59  * @param string -string to write
60  * @return negative value if error
61  */
62 int cgroup_write_node_str(const char *cgroup_name, const char *file_name,
63                           const char *string);
64
65 /**
66  * @desc make cgroup,
67  * @param parentdir - parent cgroup path
68  * @param cgroup_name - cgroup subdirectory to write
69  * @param already - true if subdir already exists, NULL pointer is possible
70  * as formal argument, in this case it will not be filled
71  * @return negative value if error
72  */
73 int cgroup_make_subdir(const char *parentdir, const char *cgroup_name,
74                        bool *already);
75
76 /**
77  * @desc write pid into cgroup_subsystem/cgroup_name file,
78  * @param cgroup_subsystem path to /sys/fs/cgroup/subsystem
79  * @param cgroup_name - name in /sys/fs/cgroup/subsystem/
80  * @return negative value if error
81  */
82 stc_error_e cgroup_write_pid(const char *cgroup_subsystem,
83                              const char *cgroup_name, const int pid);
84
85 stc_error_e cgroup_write_pid_fullpath(const char *cgroup_full_path,
86                                       const int pid);
87
88 /**
89  * @desc doing the same as @see cgroup_write_pid,
90  * but also put into cgroup first level child processes
91  */
92 stc_error_e cgroup_write_pidtree(const char *cgroup_subsystem,
93                                  const char *cgroup_name, const int pid);
94
95 /**
96  * @desc this function sets release agent path into cgroup subsystem
97  * and enables this mechanism
98  * @param cgroup_sussys - cgroup subsystem name, it's relative path to cgroup,
99  * relativelly default cgroup path (DEFAULT_CGROUP)
100  * @param release_agent full path to release agent executable
101  * @return negative value if error
102  */
103 int cgroup_set_release_agent(const char *cgroup_subsys,
104                              const char *release_agent);
105
106 /**
107  * @desc get PIDs of processes in a certain cgroup, an allocated array must be provided
108  * @return 0 if pids were read and array filled
109  */
110 int cgroup_get_pids(const char *name, GArray **pids);
111
112 /**
113  * @desc remove PID from a certain cgroup tasks file.
114  * @return 0 if pid removed
115  */
116 int cgroup_remove_pid(const char *cgroup_subsystem, const char *cgroup_name,
117                       const int pid);
118
119 #endif /*__STC_HELPER_CGROUP_H__*/