From ca29469b09faeb453e33619a99780964256777bf Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 20 May 2017 20:14:27 -0400 Subject: f --- .../include/systemd-basic/cgroup2-util.h | 109 +++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/libsystemd-basic/include/systemd-basic/cgroup2-util.h (limited to 'src/libsystemd-basic/include/systemd-basic') diff --git a/src/libsystemd-basic/include/systemd-basic/cgroup2-util.h b/src/libsystemd-basic/include/systemd-basic/cgroup2-util.h new file mode 100644 index 0000000000..cdbd9b0d9b --- /dev/null +++ b/src/libsystemd-basic/include/systemd-basic/cgroup2-util.h @@ -0,0 +1,109 @@ +#pragma once + +/*** + This file is part of systemd. + + Copyright 2010 Lennart Poettering + Copyright 2017 Luke Shumaker + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ + +#include "macro.h" + +/* generic types ****************************************************/ + +typedef struct CGroupHierarchy CGroupHierarchy; + +typedef struct CGroup { + CGroupHierarchy *hierarchy; + char *path; +} CGroup; + +static inline void cg2_freep(CGroup *cgroup) { + free(cgroup->path); +} + +static inline void cg2_free_freep(CGroup **cgroupp) { + if (*cgroupp) { + cg2_freep(*cgroupp); + free(*cgroupp); + } +} + +#define _cleanup_cgroupfree_ _cleanup_(cg2_freep) +#define _cleanup_cgroupfree_free_ _cleanup_(cg2_free_freep) + +/* generic functions ************************************************/ + +int cg2_flush(void); +bool cg2_ns_supported(void); + +int cg2_get_v1_hier(const char *controller, CGroupHierarchy **ret_hier); +int cg2_get_v2_hier(CGroupHierarchy **ret_hier); +int cg2_hier_get_version(CGroupHierarchy *hier); +char *cg2_hier_get_str(CGroupHierarchy *hier); + +int cg2_pid_get_cgroups_real(pid_t pid, /* CGroupHierarchy *hier, CGroup *ret_cgroup */...) _sentinel_; +#define cg2_pid_get_cgroups(pid, ...) cg2_pid_get_cgroups_real((pid), __VA_ARGS__, NULL) + +char *cg2_cgroup_get_filepath(CGroup cgroup); +char *cg2_cgroup_get_str(CGroup cgroup); + +/* systemd types ****************************************************/ + +typedef struct SdCGroup { + CGroup prefix; + char *path; +} SdCGroup; + +static inline void cg2_sd_freep(SdCGroup *cgroup) { + cg2_freep(&cgroup->prefix); + free(cgroup->path); +} + +static inline void cg2_sd_free_freep(SdCGroup **cgroupp) { + if (*cgroupp) { + cg2_sd_freep(*cgroupp); + free(*cgroupp); + } +} + +#define _cleanup_sdcgroupfree_ _cleanup_(cg2_sd_freep) +#define _cleanup_sdcgroupfree_free_ _cleanup_(cg2_sd_free_freep) + +typedef enum SdCGroupVersion { + CGROUP_VER_UNKNOWN = 0, + CGROUP_VER_1 = 1, + CGROUP_VER_2 = 2, /* added in systemd 230 */ + CGROUP_VER_MIXED_SD232 = 3, /* added in systemd 232 */ + CGROUP_VER_MIXED_SD233 = 4, /* added in systemd 233 */ +} SdCGroupVersion; + +/* systemd functions ************************************************/ + +int cg2_sd_flush(void); +int cg2_sd_get_version(SdCGroupVersion *ret_ver); +int cg2_sd_get_root(CGroup *ret_root); + +int cg2_sd_ver_get_hier_ver(SdCGroupVersion ver); + +int cg2_sd_pid_get_cgroup(pid_t pid, SdCGroup *ret_cgroup); + +int cg2_sd_cgroup_parse(SdCGroup cgroup, char **ret_slice, char **ret_unit, SdCGroup *ret_extra); +int cg2_sd_cgroup_get_owner_uid(SdCGroup cgroup, uid_t *ret_uid); + +char *cg2_sd_cgroup_get_filepath(SdCGroup sdcgroup); +char *cg2_sd_cgroup_get_cgpath(SdCGroup sdcgroup); +char *cg2_sd_cgroup_get_str(SdCGroup sdcgroup); -- cgit v1.2.3-54-g00ecf