return RET_NERRNO(open_by_handle_at(cgroupfs_fd, &fh.file_handle, O_DIRECTORY|O_CLOEXEC));
}
+int cg_get_cgroupid_at(int dfd, const char *path, uint64_t *ret) {
+ cg_file_handle fh = CG_FILE_HANDLE_INIT;
+ int mnt_id;
+
+ assert(dfd >= 0 || (dfd == AT_FDCWD && path_is_absolute(path)));
+ assert(ret);
+
+ /* This is cgroupfs so we know the size of the handle, thus no need to loop around like
+ * name_to_handle_at_loop() does in mountpoint-util.c */
+ if (name_to_handle_at(dfd, strempty(path), &fh.file_handle, &mnt_id, isempty(path) ? AT_EMPTY_PATH : 0) < 0) {
+ assert(errno != EOVERFLOW);
+ return -errno;
+ }
+
+ *ret = CG_FILE_HANDLE_CGROUPID(fh);
+ return 0;
+}
+
static int cg_enumerate_items(const char *controller, const char *path, FILE **ret, const char *item) {
_cleanup_free_ char *fs = NULL;
FILE *f;
return cg_path_get_machine_name(cgroup, ret_machine);
}
-int cg_path_get_cgroupid(const char *path, uint64_t *ret) {
- cg_file_handle fh = CG_FILE_HANDLE_INIT;
- int mnt_id;
-
- assert(path);
- assert(ret);
-
- /* This is cgroupfs so we know the size of the handle, thus no need to loop around like
- * name_to_handle_at_loop() does in mountpoint-util.c */
- if (name_to_handle_at(AT_FDCWD, path, &fh.file_handle, &mnt_id, 0) < 0)
- return -errno;
-
- *ret = CG_FILE_HANDLE_CGROUPID(fh);
- return 0;
-}
-
-int cg_fd_get_cgroupid(int fd, uint64_t *ret) {
- cg_file_handle fh = CG_FILE_HANDLE_INIT;
- int mnt_id = -1;
-
- assert(fd >= 0);
- assert(ret);
-
- if (name_to_handle_at(fd, "", &fh.file_handle, &mnt_id, AT_EMPTY_PATH) < 0)
- return -errno;
-
- *ret = CG_FILE_HANDLE_CGROUPID(fh);
- return 0;
-}
-
int cg_path_get_session(const char *path, char **ret_session) {
_cleanup_free_ char *unit = NULL;
char *start, *end;
int cg_path_open(const char *controller, const char *path);
int cg_cgroupid_open(int fsfd, uint64_t id);
+int cg_get_cgroupid_at(int dfd, const char *path, uint64_t *ret);
+static inline int cg_path_get_cgroupid(const char *path, uint64_t *ret) {
+ return cg_get_cgroupid_at(AT_FDCWD, path, ret);
+}
+static inline int cg_fd_get_cgroupid(int fd, uint64_t *ret) {
+ return cg_get_cgroupid_at(fd, NULL, ret);
+}
+
typedef enum CGroupFlags {
CGROUP_SIGCONT = 1 << 0,
CGROUP_IGNORE_SELF = 1 << 1,
int cg_get_root_path(char **path);
-int cg_path_get_cgroupid(const char *path, uint64_t *ret);
-int cg_fd_get_cgroupid(int fd, uint64_t *ret);
int cg_path_get_session(const char *path, char **ret_session);
int cg_path_get_owner_uid(const char *path, uid_t *ret_uid);
int cg_path_get_unit(const char *path, char **ret_unit);