Lines Matching defs:cgroup
75 char *cg_control(const char *cgroup, const char *control)
77 size_t len = strlen(cgroup) + strlen(control) + 2;
80 snprintf(ret, len, "%s/%s", cgroup, control);
86 int cg_read(const char *cgroup, const char *control, char *buf, size_t len)
91 snprintf(path, sizeof(path), "%s/%s", cgroup, control);
97 int cg_read_strcmp(const char *cgroup, const char *control,
114 if (cg_read(cgroup, control, buf, size)) {
124 int cg_read_strstr(const char *cgroup, const char *control, const char *needle)
128 if (cg_read(cgroup, control, buf, sizeof(buf)))
134 long cg_read_long(const char *cgroup, const char *control)
138 if (cg_read(cgroup, control, buf, sizeof(buf)))
144 long cg_read_key_long(const char *cgroup, const char *control, const char *key)
149 if (cg_read(cgroup, control, buf, sizeof(buf)))
159 long cg_read_lc(const char *cgroup, const char *control)
166 if (cg_read(cgroup, control, buf, sizeof(buf)))
176 int cg_write(const char *cgroup, const char *control, char *buf)
181 snprintf(path, sizeof(path), "%s/%s", cgroup, control);
186 int cg_write_numeric(const char *cgroup, const char *control, long value)
195 return cg_write(cgroup, control, buf);
209 * cgroup /sys/fs/cgroup cgroup2 rw,seclabel,noexec,relatime 0 0
227 int cg_create(const char *cgroup)
229 return mkdir(cgroup, 0755);
232 int cg_wait_for_proc_count(const char *cgroup, int count)
241 if (cg_read(cgroup, "cgroup.procs", buf, sizeof(buf)))
257 int cg_killall(const char *cgroup)
262 /* If cgroup.kill exists use it. */
263 if (!cg_write(cgroup, "cgroup.kill", "1"))
266 if (cg_read(cgroup, "cgroup.procs", buf, sizeof(buf)))
285 int cg_destroy(const char *cgroup)
289 if (!cgroup)
292 ret = rmdir(cgroup);
294 cg_killall(cgroup);
305 int cg_enter(const char *cgroup, int pid)
310 return cg_write(cgroup, "cgroup.procs", pidbuf);
313 int cg_enter_current(const char *cgroup)
315 return cg_write(cgroup, "cgroup.procs", "0");
318 int cg_enter_current_thread(const char *cgroup)
320 return cg_write(cgroup, "cgroup.threads", "0");
323 int cg_run(const char *cgroup,
324 int (*fn)(const char *cgroup, void *arg),
336 if (cg_write(cgroup, "cgroup.procs", buf))
338 exit(fn(cgroup, arg));
356 .cgroup = cgroup_fd,
421 static int clone_into_cgroup_run_nowait(const char *cgroup,
422 int (*fn)(const char *cgroup, void *arg),
428 cgroup_fd = dirfd_open_opath(cgroup);
435 exit(fn(cgroup, arg));
440 int cg_run_nowait(const char *cgroup,
441 int (*fn)(const char *cgroup, void *arg),
446 pid = clone_into_cgroup_run_nowait(cgroup, fn, arg);
459 if (cg_write(cgroup, "cgroup.procs", buf))
461 exit(fn(cgroup, arg));
495 int alloc_anon(const char *cgroup, void *arg)
582 int clone_into_cgroup_run_wait(const char *cgroup)
587 cgroup_fd = dirfd_open_opath(cgroup);
607 static int __prepare_for_wait(const char *cgroup, const char *filename)
615 ret = inotify_add_watch(fd, cg_control(cgroup, filename), IN_MODIFY);
624 int cg_prepare_for_wait(const char *cgroup)
626 return __prepare_for_wait(cgroup, "cgroup.events");
629 int memcg_prepare_for_wait(const char *cgroup)
631 return __prepare_for_wait(cgroup, "memory.events");