+int cg_enumerate_processes(const char *controller, const char *path, FILE **_f) {
+ char *fs;
+ int r;
+ FILE *f;
+
+ assert(controller);
+ assert(path);
+ assert(_f);
+
+ if ((r = cg_get_path(controller, path, "cgroup.procs", &fs)) < 0)
+ return r;
+
+ f = fopen(fs, "re");
+ free(fs);
+
+ if (!f)
+ return -errno;
+
+ *_f = f;
+ return 0;
+}
+
+int cg_enumerate_tasks(const char *controller, const char *path, FILE **_f) {
+ char *fs;
+ int r;
+ FILE *f;
+
+ assert(controller);
+ assert(path);
+ assert(_f);
+
+ if ((r = cg_get_path(controller, path, "tasks", &fs)) < 0)
+ return r;
+
+ f = fopen(fs, "re");
+ free(fs);
+
+ if (!f)
+ return -errno;
+
+ *_f = f;
+ return 0;
+}
+
+int cg_read_pid(FILE *f, pid_t *_pid) {
+ unsigned long ul;
+
+ /* Note that the cgroup.procs might contain duplicates! See
+ * cgroups.txt for details. */
+
+ errno = 0;
+ if (fscanf(f, "%lu", &ul) != 1) {
+
+ if (feof(f))
+ return 0;
+
+ return errno ? -errno : -EIO;
+ }
+
+ if (ul <= 0)
+ return -EIO;
+
+ *_pid = (pid_t) ul;
+ return 1;
+}
+