diff options
author | Jim Meyering <meyering@redhat.com> | 2007-11-10 17:31:31 +0100 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2007-11-10 18:41:14 +0100 |
commit | 56e3106e934796f993decd08b3c4224d3830209a (patch) | |
tree | 899d1c9f84823122e8eed0d2c2a13c488216f267 /src | |
parent | ca5b9746c86355cbb6c2053242b2e800a3f1ca4f (diff) | |
download | coreutils-56e3106e934796f993decd08b3c4224d3830209a.tar.xz |
install+SELinux: reduce a 12x performance hit to ~1.5x
* src/install.c (setdefaultfilecon): Call matchpathcon_init_prefix,
to mitigate what would otherwise be a large performance hit due to
the use of matchpathcon.
Dan Walsh suggested the use of matchpathcon_init_prefix.
* gl/lib/se-selinux.in.h (matchpathcon_init_prefix): Define.
Signed-off-by: Jim Meyering <meyering@redhat.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/install.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/install.c b/src/install.c index 34f61ffba..216715f5c 100644 --- a/src/install.c +++ b/src/install.c @@ -213,6 +213,38 @@ setdefaultfilecon (char const *file) if (lstat (file, &st) != 0) return; + if (IS_ABSOLUTE_FILE_NAME (file)) + { + /* Calling matchpathcon_init_prefix (NULL, "/first_component/") + is an optimization to minimize the expense of the following + matchpathcon call. */ + char const *p0; + char const *p = file + 1; + while (ISSLASH (*p)) + ++p; + + /* Record final leading slash, for when FILE starts with two or more. */ + p0 = p - 1; + + if (*p) + { + char *prefix; + do + { + ++p; + } + while (*p && !ISSLASH (*p)); + + prefix = malloc (p - p0 + 2); + if (prefix) + { + stpcpy (stpncpy (prefix, p0, p - p0), "/"); + matchpathcon_init_prefix (NULL, prefix); + free (prefix); + } + } + } + /* If there's an error determining the context, or it has none, return to allow default context */ if ((matchpathcon (file, st.st_mode, &scontext) != 0) || |