]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api.c: use /proc/self/mounts
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 31 Aug 2022 21:03:34 +0000 (15:03 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 31 Aug 2022 21:03:46 +0000 (15:03 -0600)
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 <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c

index d6f09ecfba38e0203d2de135defacf02f5afbeea..4cda82c81bc22770f5474bb4dbaa27f4a725fbbf 100644 (file)
--- 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;