From: Kamalesh Babulal Date: Wed, 31 Aug 2022 21:03:34 +0000 (-0600) Subject: api.c: use /proc/self/mounts X-Git-Tag: v3.1.0~312 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=16be308b037bbe11a54b692c227e160f1132eabe;p=thirdparty%2Flibcgroup.git api.c: use /proc/self/mounts Use /proc/self/mount instead of /proc/mounts, which is a symbolic link to the former. The symbolic link creation can be traced back to Linux Kernel commit 59c7572e82d6 ("proc: remove fs/proc/proc_misc.c"). Also, the /proc/mounts are not available in the cases where the /proc is mounted with subset=pid option. As per kernel docs filesystems/procs.rst: "subset=pid hides all top level files and directories in the procfs that are not related to tasks." Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/src/api.c b/src/api.c index d6f09ecf..4cda82c8 100644 --- a/src/api.c +++ b/src/api.c @@ -1407,7 +1407,7 @@ err: } /* - * Reads /proc/mounts and populates the cgroup v1/v2 mount points into the + * Reads /proc/self/mounts and populates the cgroup v1/v2 mount points into the * global cg_mount_table. * This function should be called with cg_mount_table_lock taken. */ @@ -1419,9 +1419,9 @@ static int cgroup_populate_mount_points(char *controllers[CG_CONTROLLER_MAX]) FILE *proc_mount; int ret = 0; - proc_mount = fopen("/proc/mounts", "re"); + proc_mount = fopen("/proc/self/mounts", "re"); if (proc_mount == NULL) { - cgroup_err("cannot open /proc/mounts: %s\n", strerror(errno)); + cgroup_err("cannot open /proc/self/mounts: %s\n", strerror(errno)); last_errno = errno; ret = ECGOTHER; goto err; @@ -1537,7 +1537,7 @@ static int cg_test_mounted_fs(void) FILE *proc_mount = NULL; int ret = 1; - proc_mount = fopen("/proc/mounts", "re"); + proc_mount = fopen("/proc/self/mounts", "re"); if (proc_mount == NULL) return 0;