xref: /linux/tools/testing/selftests/bpf/cgroup_helpers.h (revision 0ad53fe3ae82443c74ff8cfd7bd13377cc1134a3)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __CGROUP_HELPERS_H
3 #define __CGROUP_HELPERS_H
4 
5 #include <errno.h>
6 #include <string.h>
7 
8 #define clean_errno() (errno == 0 ? "None" : strerror(errno))
9 #define log_err(MSG, ...) fprintf(stderr, "(%s:%d: errno: %s) " MSG "\n", \
10 	__FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)
11 
12 /* cgroupv2 related */
13 int cgroup_setup_and_join(const char *path);
14 int create_and_get_cgroup(const char *path);
15 unsigned long long get_cgroup_id(const char *path);
16 
17 int join_cgroup(const char *path);
18 
19 int setup_cgroup_environment(void);
20 void cleanup_cgroup_environment(void);
21 
22 /* cgroupv1 related */
23 int set_classid(unsigned int id);
24 int join_classid(void);
25 
26 int setup_classid_environment(void);
27 void cleanup_classid_environment(void);
28 
29 #endif /* __CGROUP_HELPERS_H */
30