.file_handle.handle_type = FILEID_KERNFS, \
}
-/* The .f_handle field is not aligned to 64bit on some archs, hence read it via an unaligned accessor */
-#define CG_FILE_HANDLE_CGROUPID(fh) unaligned_read_ne64(fh.file_handle.f_handle)
-
int cg_is_available(void) {
struct statfs fs;
return 0;
}
-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;
-}
-
int cg_enumerate_processes(const char *path, FILE **ret) {
_cleanup_free_ char *fs = NULL;
FILE *f;
int cg_cgroupid_open(int cgroupfs_fd, uint64_t id);
int cg_path_from_cgroupid(int cgroupfs_fd, uint64_t id, char **ret);
-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,
#include "ip-protocol-list.h"
#include "limits-util.h"
#include "manager.h"
+#include "mountpoint-util.h"
#include "netlink-internal.h"
#include "nulstr-util.h"
#include "parse-util.h"
uint64_t cgroup_id = 0;
r = cg_get_path(crt->cgroup_path, /* suffix= */ NULL, &cgroup_full_path);
- if (r == 0) {
- r = cg_path_get_cgroupid(cgroup_full_path, &cgroup_id);
+ if (r < 0)
+ log_unit_warning_errno(u, r, "Failed to get full cgroup path on cgroup %s, ignoring: %m", empty_to_root(crt->cgroup_path));
+ else {
+ r = path_to_handle_u64(cgroup_full_path, &cgroup_id);
if (r < 0)
log_unit_full_errno(u, ERRNO_IS_NOT_SUPPORTED(r) ? LOG_DEBUG : LOG_WARNING, r,
"Failed to get cgroup ID of cgroup %s, ignoring: %m", cgroup_full_path);
- } else
- log_unit_warning_errno(u, r, "Failed to get full cgroup path on cgroup %s, ignoring: %m", empty_to_root(crt->cgroup_path));
+ }
crt->cgroup_id = cgroup_id;
if (r == 0)
return sd_varlink_error_invalid_parameter_name(link, "controlGroupFileDescriptor");
- r = cg_fd_get_cgroupid(fd, ret_cgroup_id);
+ r = fd_to_handle_u64(fd, ret_cgroup_id);
if (r < 0)
return log_debug_errno(r, "Failed to read cgroup ID from cgroupfs: %m");
#include "glyph-util.h"
#include "hostname-util.h"
#include "log.h"
+#include "mountpoint-util.h"
#include "nulstr-util.h"
#include "output-mode.h"
#include "path-util.h"
delegate = r > 0;
if (FLAGS_SET(flags, OUTPUT_CGROUP_ID)) {
- r = cg_fd_get_cgroupid(fd, &cgroupid);
+ r = fd_to_handle_u64(fd, &cgroupid);
if (r < 0)
log_debug_errno(r, "Failed to determine cgroup ID of %s, ignoring: %m", path);
}
#include "errno-util.h"
#include "fd-util.h"
#include "format-util.h"
+#include "mountpoint-util.h"
#include "path-util.h"
#include "pidref.h"
#include "process-util.h"
ASSERT_OK(fd_get_path(fd, &p));
ASSERT_TRUE(path_equal(p, "/sys/fs/cgroup"));
- ASSERT_OK(cg_fd_get_cgroupid(fd, &id));
+ ASSERT_OK(fd_to_handle_u64(fd, &id));
fd2 = cg_cgroupid_open(fd, id);
ASSERT_OK(fd_get_path(fd2, &p2));
ASSERT_TRUE(path_equal(p2, "/sys/fs/cgroup"));
- ASSERT_OK(cg_fd_get_cgroupid(fd2, &id2));
+ ASSERT_OK(fd_to_handle_u64(fd2, &id2));
ASSERT_EQ(id, id2);