check /proc/filesystems before /proc/mounts for selinuxfs

Al was complaining that he has selinux disabled and has 100,000+ mounts
in /proc/mounts.  Every time he runs ls the thing takes 5 seconds
because the libselinux constructor runs the entirety of his /proc/mounts
looking for selinuxfs, which doesn't exist.  Speed things up by first
checking for selinuxfs in /proc/filesystems, only if the fs is even
registered should we bother to run all of /proc/mounts.

Signed-off-by: Eric Paris <eparis@redhat.com>
This commit is contained in:
Eric Paris 2009-06-24 15:54:05 -04:00 committed by Stephen Smalley
parent bf7a7c998f
commit f057914941

View File

@ -28,6 +28,7 @@ static void init_selinuxmnt(void)
int rc;
size_t len;
ssize_t num;
int exists = 0;
if (selinux_mnt)
return;
@ -44,6 +45,23 @@ static void init_selinuxmnt(void)
}
}
/* Drop back to detecting it the long way. */
fp = fopen("/proc/filesystems", "r");
if (!fp)
return;
__fsetlocking(fp, FSETLOCKING_BYCALLER);
while ((num = getline(&buf, &len, fp)) != -1) {
if (strstr(buf, "selinuxfs")) {
exists = 1;
break;
}
}
fclose(fp);
if (!exists)
return;
/* At this point, the usual spot doesn't have an selinuxfs so
* we look around for it */
fp = fopen("/proc/mounts", "r");