- * get_init_cgroup: get the cgroup init is in.
- * @subsystem: the exact cgroup subsystem to look up (I.e. "freezer")
- * @mntent: a mntent (from getmntent) whose mntopts contains the subsystem to
- * look up.
- * @dsg: preallocated buffer of at least size MAXPATHLEN in which the path will
- * be copied.
- * @prependslash: if 1, the path will have a '/' prepended for easy of use by
- * the caller.
- *
- * subsystem and mntent can both be NULL, in which case we return
- * the first entry in /proc/1/cgroup.
- *
- * Returns a pointer to the answer (which is just the passed-in @dsg), which
- * may be "".
- */
-static char *get_init_cgroup(const char *subsystem, struct mntent *mntent,
- char *dsg, int prependslash)
-{
- FILE *f;
- char *c, *c2;
- char line[MAXPATHLEN];
- int ret;
-
- *dsg = '\0';
- f = fopen("/proc/1/cgroup", "r");
- if (!f)
- return dsg;
-
- while (fgets(line, MAXPATHLEN, f)) {
- c = index(line, ':');
- if (!c)
- continue;
- c++;
- c2 = index(c, ':');
- if (!c2)
- continue;
- *c2 = '\0';
- c2++;
- if (!subsystem && !mntent)
- goto good;
- if (subsystem && strcmp(c, subsystem) != 0)
- continue;
- if (mntent && !hasmntopt(mntent, c))
- continue;
-good:
- DEBUG("get_init_cgroup: found init cgroup for subsys %s at %s\n",
- subsystem, c2);
- ret = snprintf(dsg, MAXPATHLEN, "%s%s", prependslash ? "/" : "", c2);
- if (ret < 0 || ret >= MAXPATHLEN) {
- WARN("init cgroup path name was too long.");
- goto found;
- }
- if (ret < 1)
- goto found;
-
- c = &dsg[ret-1];
- if (*c == '\n')
- *c = '\0';
-
- goto found;
- }
-
-found:
- fclose(f);
- return dsg;
-}
-
-/*
- * Determine mountpoint for a cgroup subsystem, plus the cgroup path in that
- * subsytem of the container init.