]>
git.proxmox.com Git - mirror_lxcfs.git/blob - src/cgroups/cgroup.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
9 #include <linux/magic.h>
10 #include <linux/sched.h>
18 #include <sys/epoll.h>
19 #include <sys/mount.h>
21 #include <sys/types.h>
26 #include "../memory_utils.h"
28 #include "cgroup_utils.h"
29 #include "cgroup2_devices.h"
31 extern struct cgroup_ops
*cgfsng_ops_init(void);
33 struct cgroup_ops
*cgroup_init(void)
35 struct cgroup_ops
*ops
;
37 ops
= cgfsng_ops_init();
39 return log_error_errno(NULL
, errno
, "Failed to initialize cgroup driver");
44 void cgroup_exit(struct cgroup_ops
*ops
)
49 for (struct hierarchy
**it
= ops
->hierarchies
; it
&& *it
; it
++) {
50 for (char **p
= (*it
)->controllers
; p
&& *p
; p
++)
52 free((*it
)->controllers
);
53 free((*it
)->__controllers
);
58 free((*it
)->mountpoint
);
59 free((*it
)->base_path
);
63 if (ops
->mntns_fd
>= 0)
66 if (ops
->cgroup2_root_fd
>= 0)
67 close(ops
->cgroup2_root_fd
);
69 free(ops
->hierarchies
);
76 #define INIT_SCOPE "/init.scope"
77 void prune_init_scope(char *cg
)
84 point
= cg
+ strlen(cg
) - strlen(INIT_SCOPE
);
88 if (strcmp(point
, INIT_SCOPE
) == 0) {
96 char *get_pid_cgroup(pid_t pid
, const char *contrl
)
100 cfd
= get_cgroup_fd(contrl
);
104 if (pure_unified_layout(cgroup_ops
))
105 return cg_unified_get_current_cgroup(pid
);
107 return cg_legacy_get_current_cgroup(pid
, contrl
);
111 * Read the cpuset.cpus for cg
112 * Return the answer in a newly allocated string which must be freed
114 char *get_cpuset(const char *cg
)
119 ret
= cgroup_ops
->get_cpuset_cpus(cgroup_ops
, cg
, &value
);