mirror of
https://github.com/systemd/systemd.git
synced 2026-08-04 15:10:33 +00:00
cgroup-util: add cg_path_get_cgroupid()
It returns the cgroupID from a cgroup path.
This commit is contained in:
committed by
Iago Lopez Galeiras
parent
021d1e9612
commit
535e3dd091
@@ -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;
|
||||
|
||||
@@ -236,6 +236,7 @@ int cg_is_empty_recursive(const char *controller, const char *path);
|
||||
|
||||
int cg_get_root_path(char **path);
|
||||
|
||||
int cg_path_get_cgroupid(const char *path, uint64_t *ret);
|
||||
int cg_path_get_session(const char *path, char **session);
|
||||
int cg_path_get_owner_uid(const char *path, uid_t *uid);
|
||||
int cg_path_get_unit(const char *path, char **unit);
|
||||
|
||||
Reference in New Issue
Block a user