]>
git.proxmox.com Git - mirror_lxcfs.git/blob - src/cgroups/cgroup_utils.h
8576e5e4ec54be506871087a23f8356a6b469007
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #ifndef __LXC_CGROUP_UTILS_H
4 #define __LXC_CGROUP_UTILS_H
10 #ifndef FUSE_USE_VERSION
11 #define FUSE_USE_VERSION 26
14 #define _FILE_OFFSET_BITS 64
22 #include <sys/mount.h>
24 #include <sys/types.h>
28 #include "../config.h"
30 #include "../memory_utils.h"
32 /* Retrieve the cgroup version of a given entry from /proc/<pid>/mountinfo. */
33 extern int get_cgroup_version(char *line
);
35 /* Check if given entry from /proc/<pid>/mountinfo is a cgroupfs v1 mount. */
36 extern bool is_cgroupfs_v1(char *line
);
38 /* Check if given entry from /proc/<pid>/mountinfo is a cgroupfs v2 mount. */
39 extern bool is_cgroupfs_v2(char *line
);
41 /* Given a v1 hierarchy @mountpoint and base @path, verify that we can create
42 * directories underneath it.
44 extern bool test_writeable_v1(char *mountpoint
, char *path
);
46 /* Given a v2 hierarchy @mountpoint and base @path, verify that we can create
47 * directories underneath it and that we have write access to the cgroup's
48 * "cgroup.procs" file.
50 extern bool test_writeable_v2(char *mountpoint
, char *path
);
52 extern int unified_cgroup_hierarchy(void);
54 extern void *must_realloc(void *orig
, size_t sz
);
56 extern char *must_make_path(const char *first
, ...);
58 extern char *must_copy_string(const char *entry
);
60 /* __typeof__ should be safe to use with all compilers. */
61 typedef __typeof__(((struct statfs
*)NULL
)->f_type
) fs_type_magic
;
62 extern bool is_fs_type(const struct statfs
*fs
, fs_type_magic magic_val
);
64 extern char *lxc_string_join(const char *sep
, const char **parts
,
66 extern int lxc_count_file_lines(const char *fn
);
68 extern bool dir_exists(const char *path
);
70 extern int safe_mount(const char *src
, const char *dest
, const char *fstype
,
71 unsigned long flags
, const void *data
, const char *rootfs
);
74 extern size_t strlcpy(char *, const char *, size_t);
78 extern size_t strlcat(char *d
, const char *s
, size_t n
);
81 extern FILE *fopen_cloexec(const char *path
, const char *mode
);
82 extern void append_line(char **dest
, size_t oldlen
, char *new, size_t newlen
);
83 extern char *read_file(const char *fnam
);
84 extern char *readat_file(int fd
, const char *path
);
85 extern char *read_file_strip_newline(const char *fnam
);
86 extern char *cg_unified_get_current_cgroup(pid_t pid
);
87 extern char *cg_hybrid_get_current_cgroup(char *basecginfo
,
88 const char *controller
, int type
);
89 extern char *cg_legacy_get_current_cgroup(pid_t pid
, const char *controller
);
90 extern bool mkdir_p(const char *dir
, mode_t mode
);
91 extern bool is_cgroup_fd(int fd
);
93 static inline int openat_safe(int fd
, const char *path
)
95 return openat(fd
, path
, O_DIRECTORY
| O_RDONLY
| O_CLOEXEC
| O_NOFOLLOW
);
98 extern int cgroup_walkup_to_root(int cgroup2_root_fd
, int hierarchy_fd
,
99 const char *cgroup
, const char *file
,
102 #define must_make_path_relative(__first__, ...) \
105 if (*__first__ == '/') \
106 __ptr__ = must_make_path(".", __first__, __VA_ARGS__); \
108 __ptr__ = must_make_path(__first__, __VA_ARGS__); \
112 static inline bool is_empty_string(const char *s
)
114 return !s
|| strcmp(s
, "") == 0;
117 #endif /* __LXC_CGROUP_UTILS_H */