diff options
author | Iago López Galeiras <iagol@microsoft.com> | 2020-12-11 13:15:25 +0100 |
---|---|---|
committer | Iago Lopez Galeiras <iagol@microsoft.com> | 2021-10-06 10:52:14 +0200 |
commit | 535e3dd091aedaa47a5e349146d264f8769844c1 (patch) | |
tree | b64e0db60aae69350b797bf9d0524c939d064b3d /src/basic/cgroup-util.c | |
parent | 021d1e96123289182565f0b3ce5a705b0e84fe48 (diff) | |
download | systemd-535e3dd091aedaa47a5e349146d264f8769844c1.tar.gz |
cgroup-util: add cg_path_get_cgroupid()
It returns the cgroupID from a cgroup path.
Diffstat (limited to 'src/basic/cgroup-util.c')
-rw-r--r-- | src/basic/cgroup-util.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 9ba9f375b0..221157d57a 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -1367,6 +1367,29 @@ int cg_pid_get_machine_name(pid_t pid, char **machine) { return cg_path_get_machine_name(cgroup, machine); } +int cg_path_get_cgroupid(const char *path, uint64_t *ret) { + int mnt_id = -1; + + assert(path); + assert(ret); + + union { + struct file_handle f_handle; + uint8_t space[offsetof(struct file_handle, f_handle) + sizeof(uint64_t)]; + } buf = { + .f_handle.handle_bytes = sizeof(uint64_t), + }; + + /* 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, &buf.f_handle, &mnt_id, 0) < 0) + return -errno; + + *ret = *(uint64_t *) buf.f_handle.f_handle; + + return 0; +} + int cg_path_get_session(const char *path, char **session) { _cleanup_free_ char *unit = NULL; char *start, *end; |