From: Kamalesh Babulal Date: Wed, 31 Aug 2022 21:07:15 +0000 (-0600) Subject: api.c: use /proc/self/mounts X-Git-Tag: v2.0.3~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1686eb6f24b3f9f37e1393bd5139206dfd5e5259;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 (cherry picked from commit 16be308b037bbe11a54b692c227e160f1132eabe) --- diff --git a/src/api.c b/src/api.c index f7b6873a..0874ca1d 100644 --- a/src/api.c +++ b/src/api.c @@ -1385,9 +1385,9 @@ int cgroup_init(void) } controllers[i] = NULL; - proc_mount = fopen("/proc/mounts", "re"); + proc_mount = fopen("/proc/self/mounts", "re"); if (proc_mount == NULL) { - cgroup_err("Error: cannot open /proc/mounts: %s\n", + cgroup_err("Error: cannot open /proc/self/mounts: %s\n", strerror(errno)); last_errno = errno; ret = ECGOTHER; @@ -1463,7 +1463,7 @@ static int cg_test_mounted_fs(void) char mntent_buff[4 * FILENAME_MAX]; int ret = 1; - proc_mount = fopen("/proc/mounts", "re"); + proc_mount = fopen("/proc/self/mounts", "re"); if (proc_mount == NULL) return 0;